{#############################################################################################}
{    This code is distributed as part of the FREE!ship project. FREE!ship is an               }
{    open source surface-modelling program based on subdivision surfaces and intended for     }
{    designing ships.                                                                         }
{                                                                                             }
{    Copyright © 2005, by Martijn van Engeland                                                }
{    Copyright © 2007, by Timoshenko V.F                                                      }
{    Copyright © 2008, by Yatsenko D.V.                                                       }
{    e-mail                  : FREEship_plus@land.ru                                          }
{    FREE!ship Plus homepage : www.FREEship-plus.land.ru                                      }
{                                                                                             }
{    This program is free software; you can redistribute it and/or modify it under            }
{    the terms of the GNU General Public License as published by the                          }
{    Free Software Foundation; either version 2 of the License, or (at your option)           }
{    any later version.                                                                       }
{                                                                                             }
{    This program is distributed in the hope that it will be useful, but WITHOUT ANY          }
{    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A          }
{    PARTICULAR PURPOSE. See the GNU General Public License for more details.                 }
{                                                                                             }
{    You should have received a copy of the GNU General Public License along with             }
{    this program; if not, write to the Free Software Foundation, Inc.,                       }
{    59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                                    }
{                                                                                             }
{#############################################################################################}

unit FreeKeelWizardDlg;

{$IFDEF FPC}
  {$MODE Delphi}
{$ENDIF}

interface

uses
{$IFnDEF FPC}
  Windows,
  TeEngine,
  Series,
  TeeProcs,
  Chart,
{$ELSE}
  LCLIntf, LCLType, LMessages,
  TATools, TASeries, TACustomSeries, TAGraph, TAChartUtils, TATypes,
  TAChartAxis, TAChartAxisUtils,
  PrintersDlgs, Printer4Lazarus, FreePrinter,
  FileUtil,
{$ENDIF}
     SysUtils,
     Graphics,
     Forms,
     FreeNumInput,
     Dialogs,
     StdCtrls,
     ComCtrls,
     Controls,
     Buttons,
     Classes,
     Printers,
     FreeTypes,
     FreeGeometry,
     FreeLanguageSupport,
     FasterList,
     FreeShipUnit,
     Math,
     ExtCtrls,
     ImgList,
     ToolWin,
     Menus;


{$IFDEF FPC}
 const  clTeeColor = clTAColor;
{$ENDIF}

//   begin corrected by Victor T
const Nh           = 26;
      NacaProfiles : array[0..125,1..Nh] of double =((0.0, 0.00500, 0.00750, 0.01250, 0.02500, 0.05000, 0.07500, 0.10000, 0.15000, 0.20000, 0.25000, 0.30000, 0.35000, 0.40000, 0.45000, 0.50000, 0.55000, 0.60000, 0.65000, 0.70000, 0.75000, 0.80000, 0.85000, 0.90000, 0.95000, 1.0),  // First row contains X-coordinates
                                                    (0.0, 0.00503, 0.00609, 0.00771, 0.01057, 0.01462, 0.01766, 0.02010, 0.02386, 0.02656, 0.02841, 0.02954, 0.03000, 0.02971, 0.02877, 0.02723, 0.02517, 0.02267, 0.01982, 0.01670, 0.01342, 0.01008, 0.00683, 0.00383, 0.00138, 0.0),  // 63-006
                                                    (0.0, 0.00749, 0.00906, 0.01151, 0.01582, 0.02196, 0.02655, 0.03024, 0.03591, 0.03997, 0.04275, 0.04442, 0.04500, 0.04447, 0.04296, 0.04056, 0.03739, 0.03358, 0.02928, 0.02458, 0.01966, 0.01471, 0.00990, 0.00550, 0.00196, 0.0),  // 63-009
                                                    (0.0, 0.00829, 0.01004, 0.01275, 0.01756, 0.02440, 0.02950, 0.03362, 0.03994, 0.04445, 0.04753, 0.04938, 0.05000, 0.04938, 0.04766, 0.04496, 0.04140, 0.03715, 0.03234, 0.02712, 0.02166, 0.01618, 0.01088, 0.00604, 0.00214, 0.0),  // 63-010
                                                    (0.0, 0.00985, 0.01194, 0.01519, 0.02102, 0.02925, 0.03542, 0.04039, 0.04799, 0.05342, 0.05712, 0.05930, 0.06000, 0.05920, 0.05704, 0.05370, 0.04935, 0.04420, 0.03840, 0.03210, 0.02556, 0.01902, 0.01274, 0.00707, 0.00250, 0.0),  // 63-012
                                                    (0.0, 0.01204, 0.01462, 0.01878, 0.02610, 0.03648, 0.04427, 0.05055, 0.06011, 0.06693, 0.07155, 0.07421, 0.07500, 0.07386, 0.07099, 0.06665, 0.06108, 0.05453, 0.04721, 0.03934, 0.03119, 0.02310, 0.01541, 0.00852, 0.00300, 0.0),  // 63-015
                                                    (0.0, 0.01404, 0.01713, 0.02217, 0.03104, 0.04362, 0.05308, 0.06068, 0.07225, 0.08048, 0.08600, 0.08913, 0.09000, 0.08845, 0.08482, 0.07942, 0.07256, 0.06455, 0.05567, 0.04622, 0.03650, 0.02691, 0.01787, 0.00985, 0.00348, 0.0),  // 63-018
                                                    (0.0, 0.01583, 0.01937, 0.02527, 0.03577, 0.05065, 0.06182, 0.07080, 0.08441, 0.09410, 0.10053, 0.10412, 0.10500, 0.10298, 0.09854, 0.09206, 0.08390, 0.07441, 0.06396, 0.05290, 0.04160, 0.03054, 0.02021, 0.01113, 0.00392, 0.0),  // 63-021
                                                    (0.0,0.008160,0.009830,0.012500,0.017370,0.024120,0.029170,0.033240,0.039500,0.044000,0.047140,0.049130,0.049950,0.049680,0.048370,0.046130,0.043110,0.039430,0.035170,0.030440,0.025450,0.020400,0.015350,0.010300,0.005250,0.0), // NACA 63A010 AIRFOIL 
                                                    (0.0,0.009730,0.011730,0.014920,0.020780,0.028950,0.035040,0.039940,0.047470,0.052870,0.056640,0.059010,0.059950,0.059570,0.057920,0.055170,0.051480,0.047000,0.041860,0.036210,0.030260,0.024260,0.018260,0.012250,0.006250,0.0), // NACA 63012A AIRFOIL 
                                                    (0.0,0.012030,0.014480,0.018440,0.025790,0.036180,0.043820,0.049970,0.059420,0.066190,0.070910,0.073840,0.074960,0.074350,0.072150,0.068580,0.063870,0.058200,0.051730,0.044680,0.037310,0.029910,0.022520,0.015120,0.007720,0.0), // NACA 63-015A AIRFOIL
                                                    (0.0, 0.00494, 0.00596, 0.00754, 0.01024, 0.01405, 0.01692, 0.01928, 0.02298, 0.02572, 0.02772, 0.02907, 0.02981, 0.02995, 0.02919, 0.02775, 0.02575, 0.02331, 0.02050, 0.01740, 0.01412, 0.01072, 0.00737, 0.00423, 0.00157, 0.0),  // 64-006
                                                    (0.0, 0.00658, 0.00794, 0.01005, 0.01365, 0.01875, 0.02259, 0.02574, 0.03069, 0.03437, 0.03704, 0.03884, 0.03979, 0.03992, 0.03883, 0.03684, 0.03411, 0.03081, 0.02704, 0.02291, 0.01854, 0.01404, 0.00961, 0.00550, 0.00206, 0.0),  // 64-008
                                                    (0.0, 0.00739, 0.00892, 0.01128, 0.01533, 0.02109, 0.02543, 0.02898, 0.03455, 0.03868, 0.04170, 0.04373, 0.04479, 0.04490, 0.04364, 0.04136, 0.03826, 0.03452, 0.03026, 0.02561, 0.02069, 0.01564, 0.01069, 0.00611, 0.00227, 0.0),  // 64-009
                                                    (0.0, 0.00904, 0.00969, 0.01225, 0.01688, 0.02327, 0.02805, 0.03190, 0.03813, 0.04272, 0.04606, 0.04837, 0.04968, 0.04995, 0.04894, 0.04684, 0.04388, 0.04021, 0.03597, 0.03127, 0.02623, 0.02103, 0.01582, 0.01062, 0.00541, 0.0),  // 64-010
                                                    (0.0, 0.00978, 0.01179, 0.01490, 0.02035, 0.02810, 0.03394, 0.03871, 0.04620, 0.05173, 0.05576, 0.05844, 0.05978, 0.05981, 0.05798, 0.05480, 0.05056, 0.04548, 0.03974, 0.03350, 0.02695, 0.02029, 0.01382, 0.00786, 0.00288, 0.0),  // 64-012
                                                    (0.0, 0.01208, 0.01456, 0.01842, 0.02528, 0.03504, 0.04240, 0.04842, 0.05785, 0.06480, 0.06985, 0.07319, 0.07482, 0.07473, 0.07224, 0.06810, 0.06266, 0.05620, 0.04895, 0.04113, 0.03296, 0.02472, 0.01677, 0.00950, 0.00346, 0.0),  // 64-015
                                                    (0.0, 0.01428, 0.01720, 0.02177, 0.03005, 0.04186, 0.05076, 0.05803, 0.06942, 0.07782, 0.08391, 0.08789, 0.08979, 0.08952, 0.08630, 0.08114, 0.07445, 0.06658, 0.05782, 0.04842, 0.03866, 0.02888, 0.01951, 0.01101, 0.00400, 0.0),  // 64-018
                                                    (0.0, 0.01646, 0.01985, 0.02517, 0.03485, 0.04871, 0.05915, 0.06769, 0.08108, 0.09095, 0.09807, 0.10269, 0.10481, 0.10431, 0.10030, 0.09404, 0.08607, 0.07678, 0.06649, 0.05549, 0.04416, 0.03287, 0.02213, 0.01245, 0.00449, 0.0),  // 64-021
                                                    (0.0, 0.00476, 0.00574, 0.00717, 0.00956, 0.01310, 0.01589, 0.01824, 0.02197, 0.02482, 0.02697, 0.02852, 0.02952, 0.02998, 0.02983, 0.02900, 0.02741, 0.02518, 0.02246, 0.01935, 0.01594, 0.01233, 0.00865, 0.00510, 0.00195, 0.0),  // 65-006
                                                    (0.0, 0.00627, 0.00756, 0.00945, 0.01267, 0.01745, 0.02118, 0.02432, 0.02931, 0.03312, 0.03599, 0.03805, 0.03938, 0.03998, 0.03974, 0.03857, 0.03638, 0.03337, 0.02971, 0.02553, 0.02096, 0.01617, 0.01131, 0.00664, 0.00252, 0.0),  // 65-008
                                                    (0.0, 0.00700, 0.00845, 0.01058, 0.01421, 0.01961, 0.02383, 0.02736, 0.03299, 0.03727, 0.04050, 0.04282, 0.04431, 0.04496, 0.04469, 0.04336, 0.04086, 0.03743, 0.03328, 0.02856, 0.02342, 0.01805, 0.01260, 0.00738, 0.00280, 0.0),  // 65-009
                                                    (0.0, 0.00772, 0.00932, 0.01169, 0.01574, 0.02177, 0.02647, 0.03040, 0.03666, 0.04143, 0.04503, 0.04760, 0.04924, 0.04996, 0.04963, 0.04812, 0.04530, 0.04146, 0.03682, 0.03156, 0.02584, 0.01987, 0.01385, 0.00810, 0.00306, 0.0),  // 65-010
                                                    (0.0, 0.00923, 0.01109, 0.01387, 0.01875, 0.02606, 0.03172, 0.03647, 0.04402, 0.04975, 0.05406, 0.05716, 0.05912, 0.05997, 0.05949, 0.05757, 0.05412, 0.04943, 0.04381, 0.03743, 0.03059, 0.02345, 0.01630, 0.00947, 0.00356, 0.0),  // 65-012
                                                    (0.0, 0.01124, 0.01356, 0.01702, 0.02324, 0.03245, 0.03959, 0.04555, 0.05504, 0.06223, 0.06764, 0.07152, 0.07396, 0.07498, 0.07427, 0.07168, 0.06720, 0.06118, 0.05403, 0.04600, 0.03744, 0.02858, 0.01977, 0.01144, 0.00428, 0.0),  // 65-015
                                                    (0.0, 0.01337, 0.01608, 0.02014, 0.02751, 0.03866, 0.04733, 0.05457, 0.06606, 0.07476, 0.08129, 0.08595, 0.08886, 0.08999, 0.08901, 0.08568, 0.08008, 0.07267, 0.06395, 0.05426, 0.04396, 0.03338, 0.02295, 0.01319, 0.00490, 0.0),  // 65-018
                                                    (0.0, 0.01522, 0.01838, 0.02301, 0.03154, 0.04472, 0.05498, 0.06352, 0.07700, 0.08720, 0.09487, 0.10036, 0.10375, 0.10499, 0.10366, 0.09952, 0.09277, 0.08390, 0.07360, 0.06224, 0.05024, 0.03800, 0.02598, 0.01484, 0.00546, 0.0),  // 65-021
                                                    (0.0, 0.00687, 0.00824, 0.01030, 0.01368, 0.01880, 0.02283, 0.02626, 0.03178, 0.03601, 0.03927, 0.04173, 0.04348, 0.04457, 0.04499, 0.04475, 0.04381, 0.04204, 0.03882, 0.03428, 0.02877, 0.02263, 0.01611, 0.00961, 0.00374, 0.0),  // 66-009
                                                    (0.0, 0.00759, 0.00913, 0.01141, 0.01516, 0.02087, 0.02536, 0.02917, 0.03530, 0.04001, 0.04363, 0.04636, 0.04832, 0.04953, 0.05000, 0.04971, 0.04865, 0.04665, 0.04302, 0.03787, 0.03176, 0.02494, 0.01773, 0.01054, 0.00408, 0.0), // 66-010
                                                    (0.0,0.013230,0.015710,0.019520,0.026460,0.036900,0.045130,0.052100,0.063330,0.071880,0.078480,0.083460,0.087010,0.089180,0.089980,0.089420,0.087330,0.083230,0.075798,0.065970,0.054510,0.042060,0.029340,0.017130,0.006460,0.0),  // NACA 66-018  
                                                    (0.0,0.015250,0.018040,0.022400,0.030450,0.042690,0.052330,0.060520,0.073690,0.083760,0.091530,0.097380,0.101540,0.104070,0.105000,0.104340,0.101860,0.096920,0.087930,0.076100,0.062510,0.047960,0.033240,0.019240,0.007170,0.0),  // NACA 66-021 AIRFOIL 
                                                    (0.0,0.006276,0.007954,0.010064,0.013167,0.017806,0.021009,0.023413,0.026727,0.028688,0.029706,0.030008,0.029742,0.029017,0.027905,0.026471,0.024762,0.022816,0.020663,0.018320,0.015802,0.013116,0.010263,0.007238,0.004033,0.0),  // 0006
                                                    (0.0,0.008368,0.010605,0.013419,0.017556,0.023742,0.028012,0.031217,0.035636,0.038251,0.039608,0.040011,0.039656,0.038688,0.037207,0.035294,0.033016,0.030423,0.027550,0.024426,0.021069,0.017487,0.013684,0.009651,0.005377,0.0),  // 0008
                                                    (0.0,0.009414,0.011931,0.015097,0.019750,0.026710,0.031514,0.035120,0.040090,0.043033,0.044559,0.045012,0.044614,0.043524,0.041858,0.039706,0.037144,0.034226,0.030994,0.027480,0.023703,0.019673,0.015394,0.010858,0.006049,0.0),  // 0009
                                                    (0.0,0.010460,0.013257,0.016774,0.021944,0.029678,0.035015,0.039022,0.044545,0.047814,0.049510,0.050013,0.049571,0.048361,0.046508,0.044118,0.041270,0.038028,0.034438,0.030533,0.026336,0.021860,0.017105,0.012064,0.006721,0.0),  // 0010
                                                    (0.0,0.012552,0.015908,0.020129,0.026334,0.035614,0.042018,0.046826,0.053454,0.057377,0.059412,0.060016,0.059486,0.058032,0.055810,0.052941,0.049524,0.045634,0.041325,0.036640,0.031604,0.026231,0.020525,0.014477,0.008066,0.0),  // 0012
                                                    (0.0,0.015691,0.019885,0.025161,0.032917,0.044517,0.052522,0.058532,0.066817,0.071721,0.074265,0.075020,0.074356,0.072540,0.069763,0.066177,0.061905,0.057042,0.051657,0.045800,0.039505,0.032789,0.025657,0.018096,0.010082,0.0),  // 0015
                                                    (0.0,0.018829,0.023862,0.030193,0.039500,0.053420,0.063027,0.070239,0.080180,0.086065,0.089119,0.090024,0.089228,0.087049,0.083715,0.079412,0.074287,0.068450,0.061988,0.054960,0.047405,0.039347,0.030788,0.021715,0.012099,0.0),  // 0018
                                                    (0.0,0.020921,0.026513,0.033548,0.043889,0.059356,0.070029,0.078043,0.089089,0.095628,0.099021,0.100027,0.099142,0.096721,0.093017,0.088236,0.082540,0.076056,0.068876,0.061067,0.052673,0.043719,0.034209,0.024129,0.013443,0.0),  // 0020
                                                    (0.0,0.021967,0.027839,0.035225,0.046084,0.062324,0.073531,0.081946,0.093543,0.100410,0.103971,0.105028,0.104099,0.101557,0.097668,0.092648,0.086667,0.079858,0.072319,0.064120,0.055306,0.045905,0.035920,0.025335,0.014114,0.0),  // 0021
                                                    (0.0,0.026151,0.033142,0.041935,0.054861,0.074195,0.087537,0.097554,0.111361,0.119535,0.123775,0.125033,0.123928,0.120901,0.116271,0.110295,0.103176,0.095070,0.086095,0.076333,0.065841,0.054649,0.042762,0.030160,0.016804,0.0),  // 0025
                                                    (0.0,0.031381,0.039770,0.050322,0.065834,0.089034,0.105044,0.117065,0.133634,0.143443,0.148531,0.150040,0.148713,0.145081,0.139525,0.132353,0.123811,0.114084,0.103314,0.091600,0.079009,0.065578,0.051314,0.036193,0.020164,0.0),  // 0030
                                                    (0.0,0.036611,0.046398,0.058708,0.076806,0.103873,0.122552,0.136576,0.155906,0.167350,0.173286,0.175047,0.173499,0.169261,0.162779,0.154413,0.144446,0.133097,0.120532,0.106866,0.092177,0.076508,0.059866,0.042224,0.023524,0.0),  // 0035
                                                    ( 0.0,0.006675,0.008445,0.010515,0.014066,0.019035,0.022380,0.024793,0.027888,0.029416,0.029865,0.029509,0.028529,0.027056,0.025193,0.023026,0.020623,0.018053,0.015381,0.012667,0.009976,0.007372,0.004936,0.002763,0.001004, 0.0), // НЕЖ 06
                                                    ( 0.0,0.008925,0.011276,0.013947,0.018762,0.025394,0.029869,0.033097,0.037242,0.039298,0.039912,0.039449,0.038150,0.036189,0.033703,0.030809,0.027600,0.024164,0.020588,0.016956,0.013352,0.009867,0.006606,0.003698,0.001344, 0.0), // НЕЖ 08
                                                    ( 0.0,0.010039,0.012675,0.015625,0.021082,0.028537,0.033573,0.037208,0.041876,0.044197,0.044897,0.044386,0.042932,0.040731,0.037939,0.034683,0.031074,0.027208,0.023183,0.019093,0.015035,0.011111,0.007437,0.004163,0.001513, 0.0), // НЕЖ 09
                                                    ( 0.0,0.011154,0.014070,0.017287,0.023390,0.031667,0.037264,0.041305,0.046500,0.049088,0.049878,0.049321,0.047715,0.045277,0.042179,0.038563,0.034554,0.030258,0.025784,0.021236,0.016722,0.012358,0.008271,0.004630,0.001682, 0.0), // НЕЖ 10
                                                    ( 0.0,0.013367,0.016838,0.020554,0.027971,0.037881,0.044602,0.049459,0.055711,0.058844,0.059824,0.059187,0.057286,0.054380,0.050676,0.046344,0.041535,0.036381,0.031005,0.025539,0.020111,0.014860,0.009946,0.005567,0.002022, 0.0), // НЕЖ 12
                                                    ( 0.0,0.016631,0.020907,0.025291,0.034708,0.047034,0.055430,0.061513,0.069359,0.073335,0.074631,0.073905,0.071593,0.068013,0.063421,0.058030,0.052029,0.045590,0.038866,0.032019,0.025214,0.018630,0.012467,0.006977,0.002534, 0.0), // НЕЖ 15
                                                    ( 0.0,0.019849,0.024904,0.029870,0.041324,0.056044,0.066118,0.073438,0.082907,0.087778,0.089436,0.088661,0.085975,0.081754,0.076297,0.069859,0.062668,0.054932,0.046849,0.038605,0.030404,0.022463,0.015029,0.008410,0.003052, 0.0), // НЕЖ 18
                                                    ( 0.0,0.021960,0.027517,0.032832,0.045652,0.061949,0.073141,0.081292,0.091860,0.097357,0.099287,0.098510,0.095596,0.090968,0.084951,0.077825,0.069845,0.061243,0.052243,0.043059,0.033915,0.025056,0.016762,0.009378,0.003402, 0.0), // НЕЖ 20
                                                    ( 0.0,0.022990,0.028793,0.034272,0.047770,0.064847,0.076586,0.085149,0.096269,0.102084,0.104158,0.103390,0.100373,0.095550,0.089260,0.081797,0.073427,0.064395,0.054940,0.045286,0.035671,0.026353,0.017629,0.009861,0.003577, 0.0), // НЕЖ 21
                                                    ( 0.0,0.027035,0.033789,0.040133,0.056068,0.076258,0.090153,0.100377,0.113754,0.120902,0.123625,0.122960,0.119595,0.114038,0.106697,0.097911,0.087992,0.077237,0.065934,0.054372,0.042837,0.031647,0.021163,0.011833,0.004284, 0.0), // НЕЖ 25
                                                    ( 0.0,0.031819,0.039692,0.047174,0.065896,0.089846,0.106382,0.118652,0.134917,0.143861,0.147559,0.147201,0.143572,0.137253,0.128714,0.118365,0.106567,0.093676,0.080050,0.066050,0.052053,0.038455,0.025706,0.014359,0.005186, 0.0), // НЕЖ 30
                                                    ( 0.0,0.036294,0.045217,0.053780,0.075138,0.102688,0.121801,0.136087,0.155310,0.166200,0.171074,0.171246,0.167576,0.160698,0.151132,0.139334,0.125732,0.110732,0.094758,0.078255,0.061690,0.045567,0.030443,0.016984,0.006122, 0.0), // НЕЖ 35
                                                    ( 0.0,0.010485,0.013274,0.016715,0.024547,0.035454,0.043201,0.049051,0.056816,0.060808,0.062199,0.061707,0.059780,0.056754,0.052912,0.048483,0.043639,0.038537,0.033314,0.028076,0.022929,0.017962,0.013251,0.008867,0.004628, 0.0 ), // E168 (12.5%) 
                                                    ( 0.0, 0.011633, 0.014736, 0.018543, 0.027310, 0.039676, 0.048578, 0.055406, 0.064725, 0.069832, 0.071893, 0.071549, 0.069246, 0.065542, 0.060869, 0.055531, 0.049749, 0.043716, 0.037577, 0.031473, 0.025519, 0.019821, 0.014476, 0.009549, 0.004881, 0.0 ), // E169 (14.4%) 
                                                    ( 0.0, 0.008609, 0.010974, 0.013872, 0.020508, 0.029866, 0.036692, 0.042050, 0.049970, 0.055336, 0.058838, 0.060816, 0.061405, 0.060559, 0.058279, 0.054689, 0.050020, 0.044623, 0.038831, 0.032862, 0.026875, 0.021021, 0.015424, 0.010173, 0.005157, 0.0 ), // E171(Dicke 12.28%) 
                                                    ( 0.0, 0.007307, 0.009389, 0.012610, 0.018763, 0.027323, 0.033514, 0.038352, 0.045512, 0.050433, 0.053760, 0.055828, 0.056815, 0.056838, 0.055963, 0.054209, 0.051567, 0.047992, 0.043392, 0.037562, 0.030563, 0.023078, 0.015846, 0.009284, 0.003782, 0.0 ), //EPPLER 297 AIRFOIL 
                                                    ( 0.0, 0.013975, 0.017392, 0.021856, 0.031524, 0.043866, 0.051383, 0.056054, 0.060068, 0.060393, 0.059168, 0.057104, 0.054495, 0.051519, 0.048270, 0.044819, 0.041211, 0.037481, 0.033646, 0.029720, 0.025699, 0.021567, 0.017291, 0.012757, 0.007425, 0.0 ), //EPPLER 472 AIRFOIL 
                                                    ( 0.0, 0.014911, 0.018782, 0.023629, 0.034691, 0.050003, 0.060596, 0.068269, 0.077522, 0.080839, 0.080113, 0.077360, 0.073598, 0.069202, 0.064395, 0.059303, 0.054012, 0.048592, 0.043084, 0.037513, 0.031902, 0.026257, 0.020550, 0.014702, 0.008184, 0.0 ), //EPPLER 473 AIRFOIL 
                                                    ( 0.0, 0.013855, 0.017457, 0.022036, 0.032309, 0.046166, 0.055381, 0.061711, 0.068591, 0.070466, 0.069772, 0.067827, 0.065114, 0.061871, 0.058241, 0.054313, 0.050136, 0.045755, 0.041182, 0.036416, 0.031442, 0.026198, 0.020435, 0.013659, 0.006341, 0.0 ), //E474 (14.09%) 
                                                    ( 0.0, 0.014296, 0.018035, 0.022749, 0.033383, 0.047834, 0.057568, 0.064382, 0.072153, 0.074822, 0.074794, 0.073408, 0.071147, 0.068270, 0.064915, 0.061162, 0.057081, 0.052685, 0.047986, 0.042984, 0.037608, 0.031748, 0.025001, 0.016571, 0.007426, 0.0 ), //E475 (15.01%) 
                                                    ( 0.0, 0.011197, 0.014327, 0.019175, 0.028526, 0.041697, 0.051283, 0.058765, 0.069663, 0.076797, 0.081175, 0.083343, 0.083647, 0.082333, 0.079593, 0.075566, 0.070387, 0.064144, 0.056919, 0.048746, 0.039842, 0.030767, 0.021981, 0.013796, 0.006341, 0.0 ), //EPPLER 476 AIRFOIL 
                                                    ( 0.0, 0.010629, 0.013605, 0.018214, 0.027037, 0.039401, 0.048308, 0.055199, 0.065092, 0.071381, 0.075060, 0.076647, 0.076487, 0.074832, 0.071870, 0.067751, 0.062625, 0.056618, 0.049855, 0.042501, 0.034774, 0.026991, 0.019447, 0.012384, 0.005847, 0.0 ), //EPPLER 477 AIRFOIL 
                                                    ( 0.0, 0.013200, 0.016840, 0.022437, 0.032932, 0.047081, 0.056740, 0.063779, 0.072796, 0.077289, 0.078537, 0.077348, 0.074514, 0.070547, 0.065740, 0.060333, 0.054489, 0.048339, 0.042030, 0.035650, 0.029301, 0.023079, 0.017070, 0.011342, 0.005736, 0.0 ), //EPPLER 478 AIRFOIL 
                                                    ( 0.0, 0.014816, 0.018653, 0.023460, 0.034285, 0.049021, 0.059182, 0.066653, 0.076391, 0.081376, 0.082869, 0.081688, 0.078687, 0.074463, 0.069321, 0.063522, 0.057262, 0.050678, 0.043925, 0.037120, 0.030374, 0.023785, 0.017459, 0.011475, 0.005715, 0.0 ), //EPPLER 479 AIRFOIL 
                                                    ( 0.0, 0.009948, 0.012732, 0.017038, 0.025298, 0.036874, 0.045250, 0.051779, 0.061339, 0.067721, 0.071858, 0.074233, 0.075076, 0.074545, 0.072720, 0.069622, 0.065088, 0.058970, 0.051187, 0.042100, 0.032798, 0.024096, 0.016260, 0.009492, 0.003922, 0.0 ), //EPPLER 520 AIRFOIL 
                                                    ( 0.0, 0.009365, 0.011998, 0.016068, 0.023829, 0.034639, 0.042366, 0.048329, 0.056927, 0.062555, 0.066151, 0.068172, 0.068883, 0.068460, 0.067003, 0.064547, 0.061051, 0.056351, 0.050276, 0.042710, 0.033951, 0.025078, 0.016954, 0.009880, 0.004066, 0.0 ), //EPPLER 521 AIRFOIL 
                                                    ( 0.0, 0.007728, 0.009918, 0.012626, 0.018874, 0.027797, 0.034446, 0.039767, 0.047904, 0.053743, 0.057951, 0.060841, 0.062581, 0.063268, 0.062906, 0.061390, 0.058601, 0.054508, 0.049160, 0.042640, 0.035167, 0.027246, 0.019419, 0.012076, 0.005462, 0.0 ), //EPPLER E836 HYDROFOIL AIRFOIL 
                                                    ( 0.0, 0.009745, 0.012526, 0.015957, 0.023978, 0.035582, 0.044349, 0.051415, 0.062243, 0.069935, 0.075315, 0.078735, 0.080372, 0.080214, 0.078208, 0.074425, 0.068994, 0.062095, 0.054059, 0.045394, 0.036564, 0.027876, 0.019620, 0.012063, 0.005380, 0.0 ), //EPPLER E837 HYDROFOIL AIRFOIL 
                                                    ( 0.0, 0.010109, 0.012998, 0.016505, 0.024812, 0.036966, 0.046390, 0.054205, 0.066690, 0.076110, 0.083171, 0.088165, 0.091175, 0.092060, 0.090668, 0.086995, 0.081128, 0.073253, 0.063800, 0.053497, 0.042973, 0.032633, 0.022839, 0.013915, 0.006095, 0.0 ), //EPPLER E838 HYDROFOIL AIRFOIL 
                                                    ( 0.0, 0.027045, 0.033623, 0.041683, 0.060299, 0.086386, 0.105213, 0.119810, 0.140652, 0.153590, 0.160367, 0.161769, 0.158472, 0.151280, 0.141427, 0.129981, 0.117559, 0.104571, 0.091319, 0.078014, 0.064997, 0.052515, 0.040487, 0.028807, 0.017343, 0.0 ), //EPPLER 862 STRUT AIRFOIL 
                                                    ( 0.0, 0.030821, 0.038405, 0.047487, 0.068723, 0.098741, 0.120662, 0.138782, 0.163500, 0.180401, 0.190441, 0.194403, 0.192510, 0.185292, 0.174510, 0.161703, 0.147655, 0.132859, 0.117659, 0.102285, 0.086804, 0.071200, 0.055493, 0.039705, 0.023863, 0.0 ), //EPPLER 864 STRUT AIRFOIL 
                                                    ( 0.0, 0.007320, 0.010590, 0.015454, 0.022617, 0.026400, 0.031328, 0.034800, 0.039463, 0.042000, 0.044025, 0.045000, 0.044775, 0.043800, 0.042625, 0.040800, 0.037969, 0.034400, 0.030238, 0.025500, 0.020038, 0.014500, 0.009348, 0.005000, 0.002100, 0.0 ), //EPPLER EA 6(-1)-009 AIRFOIL 
                                                    ( 0.0, 0.009675, 0.014006, 0.020525, 0.030350, 0.036000, 0.041883, 0.045600, 0.051825, 0.055800, 0.058575, 0.060000, 0.060175, 0.059400, 0.058238, 0.056000, 0.051988, 0.046800, 0.040750, 0.034000, 0.026463, 0.019200, 0.013488, 0.008600, 0.004200, 0.0 ), //EPPLER EA 6(-1)-012 AIRFOIL 
                                                    ( 0.0, 0.005402, 0.007802, 0.011281, 0.016100, 0.017800, 0.021206, 0.023800, 0.027121, 0.028800, 0.029725, 0.030000, 0.030088, 0.029800, 0.029044, 0.028000, 0.026906, 0.025500, 0.023594, 0.021200, 0.018194, 0.014800, 0.011179, 0.007400, 0.003600, 0.0 ), //EPPLER EA 8(-1)-006 AIRFOIL 
                                                    (0.0,0.008756,0.012456,0.018500,0.026419,0.034500,0.041000,0.047000,0.054000,0.058500,0.061646,0.063500,0.064125,0.063500,0.061438,0.058500,0.055281,0.051500,0.047063,0.042000,0.036344,0.030000,0.022854,0.015000,0.006500,0.0), // GOE 409 AIRFOIL 
                                                    (0.0,0.012260,0.017460,0.026000,0.036500,0.050500,0.059000,0.065000,0.072500,0.078000,0.080490,0.080500,0.078375,0.074500,0.069188,0.063000,0.056656,0.050000,0.043063,0.036000,0.028875,0.022000,0.015792,0.010000,0.004500,0.0), // GOE 410 AIRFOIL 
                                                    (0.0,0.005152,0.007452,0.011500,0.018400,0.030500,0.038800,0.046000,0.055000,0.060500,0.064083,0.066000,0.066406,0.065500,0.063438,0.060500,0.057000,0.053000,0.048781,0.044000,0.038313,0.032000,0.025375,0.018000,0.009500,0.0), // GOE 411 AIRFOIL 
                                                    (0.0,0.002820,0.004020,0.006000,0.008500,0.011500,0.014000,0.016000,0.019125,0.021500,0.023594,0.025000,0.025313,0.025000,0.024438,0.023500,0.022156,0.020500,0.018625,0.016500,0.014063,0.011500,0.009094,0.006500,0.003438,0.0), // GOE 443 AIRFOIL 
                                                    (0.0,0.002760,0.003960,0.006000,0.009000,0.013000,0.016000,0.019000,0.023000,0.025500,0.027115,0.028000,0.028219,0.028000,0.027688,0.027000,0.025719,0.024000,0.021906,0.019500,0.016844,0.014000,0.011115,0.008000,0.004500,0.0), // GOE 444 AIRFOIL 
                                                    (0.0,0.003220,0.004620,0.007000,0.010500,0.015500,0.019000,0.022000,0.026500,0.029000,0.030583,0.031500,0.032063,0.032000,0.031031,0.029500,0.027625,0.025500,0.023375,0.021000,0.018138,0.015000,0.011769,0.008300,0.004500,0.0), // GOE 445 AIRFOIL 
                                                    (0.0,0.008340,0.011940,0.018000,0.026500,0.036000,0.043000,0.048500,0.055500,0.060000,0.062458,0.063500,0.063781,0.063000,0.060938,0.058000,0.054563,0.050500,0.045750,0.040500,0.034938,0.029000,0.022677,0.016000,0.009000,0.0), // GOE 459 AIRFOIL 
                                                    (0.0,0.012860,0.018360,0.027500,0.039500,0.055500,0.067500,0.076000,0.089000,0.096000,0.100406,0.102500,0.102406,0.100500,0.097156,0.092500,0.086719,0.080000,0.072688,0.064500,0.055125,0.045000,0.034583,0.023500,0.011500,0.0), // GOE 460 AIRFOIL 
                                                    (0.0,0.015765,0.022411,0.033230,0.045850,0.062310,0.073660,0.082020,0.093830,0.100740,0.104454,0.105660,0.104864,0.102380,0.098678,0.093800,0.087885,0.081120,0.073724,0.065740,0.057406,0.048360,0.038126,0.027280,0.016290,0.0), // GOE 775 AIRFOIL 
                                                    (0.0,0.018751,0.026657,0.039530,0.054570,0.074130,0.087690,0.097760,0.111690,0.120020,0.124415,0.125780,0.124810,0.121840,0.117414,0.111600,0.104593,0.096560,0.087734,0.078120,0.067813,0.056780,0.045033,0.032540,0.019270,0.0), // GOE 776 AIRFOIL 
                                                    (0.0,0.006296,0.008976,0.013400,0.019000,0.026700,0.032000,0.036200,0.042400,0.046000,0.048004,0.048800,0.048731,0.047800,0.046063,0.043700,0.040950,0.037700,0.033825,0.029600,0.025294,0.020800,0.016100,0.011200,0.006100,0.0), // RAF 27 AIRFOIL  
                                                    (0.0,0.008544,0.012144,0.018000,0.024800,0.034600,0.041604,0.046800,0.054400,0.059400,0.062129,0.063200,0.063175,0.062000,0.059775,0.056600,0.052538,0.047800,0.042600,0.037000,0.031075,0.025000,0.019000,0.013000,0.007000,0.0), // RAF 30 AIRFOIL  
                                                    (0.0,0.005124,0.007284,0.010800,0.014900,0.020800,0.025000,0.028100,0.032600,0.035600,0.037300,0.038000,0.037950,0.037200,0.035881,0.034000,0.031556,0.028700,0.025569,0.022200,0.018644,0.015000,0.011438,0.007800,0.003975,0.0), // RAF 30 MOD AIRFOIL  
                                                    (0.0,0.007577,0.009422,0.011721,0.016514,0.022170,0.025373,0.027313,0.029278,0.029997,0.030091,0.029800,0.029236,0.028451,0.027479,0.026343,0.025026,0.023507,0.021718,0.019487,0.016650,0.013344,0.009864,0.006395,0.003023,0.0), // S1010 HPV airfoil  
                                                    (0.0,0.012350,0.015136,0.018558,0.025923,0.035140,0.041041,0.045283,0.051105,0.054916,0.057483,0.059111,0.059958,0.060105,0.059577,0.058371,0.056434,0.053634,0.049699,0.044003,0.036363,0.027810,0.019378,0.011588,0.004823,0.0), // S1012   
                                                    (0.0,0.013980,0.017313,0.021267,0.030132,0.041826,0.049838,0.055930,0.064895,0.071262,0.075904,0.079206,0.081338,0.082399,0.082427,0.081375,0.079148,0.075558,0.070031,0.061289,0.049467,0.036903,0.025052,0.014510,0.005755,0.0), // S1014   
                                                    (0.0,0.015122,0.018760,0.023092,0.032917,0.046037,0.055071,0.061875,0.071586,0.078112,0.082566,0.085459,0.087057,0.087521,0.086921,0.085267,0.082525,0.078554,0.073131,0.065613,0.054705,0.041197,0.027864,0.016016,0.006269,0.0), // S1016   
                                                    (0.0,0.012758,0.016314,0.020747,0.031010,0.045493,0.055942,0.063945,0.075044,0.081504,0.084558,0.085068,0.083606,0.080560,0.076219,0.070823,0.064550,0.057498,0.049851,0.041988,0.034128,0.026435,0.019031,0.012068,0.005659,0.0), //  S1046 17% (Danny Howell)  
                                                    (0.0,0.010105,0.012978,0.016603,0.024904,0.036707,0.045271,0.051864,0.061106,0.066617,0.069381,0.069975,0.068837,0.066324,0.062719,0.058251,0.053084,0.047362,0.041229,0.034903,0.028557,0.022300,0.016233,0.010460,0.005049,0.0), //  S1048 14% (Danny Howell)  
                                                    (0.0,0.012135,0.015096,0.019851,0.028662,0.040418,0.048545,0.054523,0.062606,0.067255,0.069490,0.069991,0.069062,0.067023,0.064021,0.060239,0.055757,0.050714,0.045154,0.039221,0.032966,0.026530,0.020022,0.013718,0.007398,0.0), //  S8035 for RC aerobatic 14% thick  
                                                    (0.0,0.009402,0.011793,0.014695,0.021230,0.029898,0.035708,0.039955,0.045574,0.048726,0.050230,0.050523,0.049878,0.048485,0.046460,0.043894,0.040864,0.037422,0.033614,0.029493,0.025110,0.020535,0.015833,0.011020,0.005773,0.0), //  SD8020-010-88  
                                                    (0.0,0.004960,0.007020,0.010300,0.013600,0.018000,0.021000,0.023400,0.026700,0.028800,0.030127,0.030800,0.030900,0.030500,0.029681,0.028500,0.027056,0.025300,0.023188,0.020800,0.018213,0.015400,0.012348,0.009100,0.005700,0.0), // NACA-M1 AIRFOIL 
                                                    (0.0,0.006232,0.008832,0.013000,0.017400,0.023300,0.026515,0.028400,0.031800,0.034900,0.037800,0.040000,0.040529,0.040000,0.038975,0.037400,0.035406,0.033000,0.030225,0.027100,0.023656,0.019900,0.015992,0.011500,0.006000,0.0), // NACA M2 AIRFOIL 
                                                    (0.0,0.008892,0.012612,0.018600,0.025100,0.033900,0.040000,0.044700,0.051400,0.055700,0.058275,0.059500,0.059681,0.058900,0.057319,0.055000,0.052063,0.048500,0.044319,0.039600,0.034431,0.028800,0.022713,0.016200,0.009300,0.0), // NACA M3 AIRFOIL 
                                                    (0.0,0.008397,0.010623,0.014017,0.019847,0.026864,0.031603,0.035224,0.040216,0.043144,0.044660,0.045108,0.044688,0.043584,0.041918,0.039780,0.037232,0.034328,0.031108,0.027605,0.023840,0.019815,0.015534,0.010955,0.005930,0.0), // NACA-0009 9.0% smoothed 
                                                    (0.0,0.012242,0.014874,0.018954,0.026149,0.035548,0.042000,0.046830,0.053454,0.057370,0.059417,0.060020,0.059482,0.058026,0.055809,0.052941,0.049525,0.045633,0.041328,0.036639,0.031603,0.026227,0.020526,0.014476,0.008065,0.0), // NACA 0012 AIRFOILS  
                                                    (0.0,0.006460,0.007780,0.009830,0.013530,0.018630,0.022450,0.025590,0.030470,0.034140,0.036810,0.038660,0.039720,0.039980,0.039210,0.037570,0.035240,0.032340,0.028970,0.025210,0.021170,0.016980,0.012780,0.008580,0.004380,0.0), // NACA 64-008A AIRFOIL 
                                                    (0.0,0.008150,0.009800,0.012343,0.016949,0.023310,0.028076,0.032010,0.038155,0.042740,0.046080,0.048370,0.049680,0.049950,0.048930,0.046830,0.043870,0.040210,0.035970,0.031240,0.026200,0.021020,0.015830,0.010630,0.005400,0.0), // NACA 64A-010 10.0% 
                                                    (0.0,0.009610,0.011580,0.014640,0.020180,0.027880,0.033640,0.038390,0.045800,0.051320,0.055340,0.058090,0.059650,0.059930,0.058630,0.056050,0.052440,0.048010,0.042890,0.037210,0.031180,0.025000,0.018820,0.012630,0.006440,0.0), // NACA 64-012A AIRFOIL 
                                                    (0.0,0.012080,0.014560,0.018420,0.025280,0.035040,0.042400,0.048420,0.057850,0.064800,0.069850,0.073190,0.074820,0.074730,0.072240,0.068100,0.062660,0.056200,0.048950,0.041130,0.032960,0.024720,0.016770,0.009500,0.003460,0.0), // NACA 642-015 AIRFOIL 
                                                    (0.0,0.011930,0.014360,0.018150,0.025080,0.034770,0.042020,0.047990,0.057320,0.064230,0.069260,0.072700,0.074630,0.074870,0.073130,0.069780,0.065170,0.059560,0.053110,0.046000,0.038470,0.030840,0.023210,0.015580,0.007950,0.0), // NACA 642-015A AIRFOIL
                                                    (0.0,0.011404,0.014924,0.018896,0.025964,0.034656,0.040677,0.045386,0.052442,0.057507,0.060924,0.063053,0.064072,0.064320,0.063743,0.062042,0.058976,0.054499,0.048716,0.041845,0.034318,0.026413,0.018643,0.011744,0.006356,0.0), // NACA/LANGLEY LS(1)-0013 AIRFOIL 
                                                    (0.0,0.009780,0.011790,0.014900,0.020350,0.028100,0.033940,0.038710,0.046200,0.051730,0.055760,0.058440,0.059780,0.059810,0.057980,0.054800,0.050560,0.045480,0.039740,0.033500,0.026950,0.020290,0.013820,0.007890,0.002880,0.0), // NASA/LANGLEY 64-012 AIRFOIL 
                                                    (0.0,0.014814,0.016696,0.020320,0.026210,0.033370,0.038120,0.041640,0.046610,0.049900,0.052120,0.053590,0.054470,0.054780,0.054570,0.053760,0.052380,0.050410,0.047820,0.044560,0.040500,0.035490,0.029310,0.021620,0.012030,0.0), // NACA/LANGLEY SYMMETRICAL, SUPERCRITICAL AIRFOIL 
                                                    (0.0,0.005738,0.007217,0.009402,0.013367,0.018674,0.022406,0.025358,0.029775,0.032109,0.033690,0.034628,0.034987,0.034408,0.033311,0.031770,0.029546,0.026676,0.023288,0.019629,0.015890,0.012145,0.008541,0.005364,0.002343,0.0), // HQ 0/7 AIRFOIL 
                                                    (0.0,0.006660,0.008370,0.010899,0.015493,0.021643,0.025975,0.029395,0.034514,0.037223,0.039050,0.040145,0.040557,0.039895,0.038613,0.036830,0.034252,0.030922,0.026993,0.022754,0.018430,0.014075,0.009900,0.006219,0.002711,0.0), // HQ 0/9 AIRFOIL 
                                                    (0.0,0.008204,0.010315,0.013437,0.019097,0.026680,0.032016,0.036230,0.042549,0.045878,0.048140,0.049481,0.049995,0.049168,0.047592,0.045390,0.042218,0.038111,0.033279,0.028043,0.022710,0.017353,0.012203,0.007665,0.003346,0.0), // HQ 0/10 AIRFOIL 
                                                    (0.0,0.013181,0.016121,0.020571,0.027648,0.033805,0.037541,0.040113,0.043059,0.044426,0.044670,0.044299,0.043343,0.041875,0.039922,0.037630,0.034918,0.031937,0.028673,0.025153,0.021330,0.017361,0.013242,0.009032,0.004732,0.0), // WORTMANN FX 71-089A AIRFOIL 
                                                    (0.0,0.015252,0.018805,0.024172,0.033879,0.044101,0.049297,0.052837,0.057297,0.059428,0.059930,0.059536,0.058313,0.056385,0.053790,0.050720,0.047099,0.043101,0.038690,0.033924,0.028790,0.023412,0.017846,0.012183,0.006369,0.0), // FX 71-120 AIRFOIL 
                                                    (0.0,0.015580,0.017911,0.021428,0.028830,0.039021,0.046572,0.052632,0.061670,0.067972,0.072140,0.074445,0.075025,0.073802,0.070945,0.066300,0.059918,0.052027,0.043300,0.034219,0.025270,0.017050,0.011476,0.007440,0.003733,0.0), // FX 71-L-150/20 AIRFOIL 
                                                    (0.0,0.015389,0.017736,0.021280,0.028709,0.038924,0.046481,0.052529,0.061583,0.067870,0.072040,0.074373,0.075024,0.073959,0.071278,0.066890,0.060964,0.054200,0.046006,0.036928,0.027710,0.019717,0.014136,0.008892,0.004129,0.0), // FX 71-L-150/25 AIRFOIL 
                                                    (0.0,0.015580,0.017911,0.021428,0.028830,0.039021,0.046572,0.052632,0.061670,0.067972,0.072140,0.074442,0.075025,0.073802,0.070945,0.066300,0.059918,0.052027,0.043300,0.034219,0.025270,0.017050,0.011476,0.007440,0.003733,0.0), // FX 71-L-150/K30 AIRFOIL 
                                                    (0.0,0.010895,0.014022,0.018891,0.027407,0.038219,0.045948,0.051774,0.060108,0.066015,0.069401,0.070957,0.070535,0.068342,0.064704,0.058997,0.052793,0.045924,0.039096,0.032128,0.025996,0.019907,0.014145,0.009242,0.004641,0.0), // FX LIII-142 K25 AIRFOIL 
                                                    (0.0,0.010308,0.013579,0.018428,0.026689,0.038204,0.046223,0.052664,0.061963,0.068877,0.073401,0.075554,0.076489,0.075508,0.072454,0.067997,0.061293,0.053802,0.045558,0.037760,0.029593,0.022458,0.015457,0.009377,0.004467,0.0), // FX L V-152 AIRFOIL 
                                                    (0.0,0.012279,0.014934,0.018570,0.025108,0.033205,0.038452,0.042135,0.046546,0.048360,0.048357,0.047018,0.044637,0.041493,0.038198,0.034915,0.031628,0.028339,0.025054,0.021770,0.018481,0.015194,0.011911,0.008616,0.005333,0.0), // BELL 540 AIRFOIL (MODIFIED NACA 0012)  
                                                    (0.0,0.009989,0.012091,0.015302,0.021083,0.028615,0.033805,0.037697,0.043128,0.046531,0.048541,0.049422,0.049343,0.048386,0.046627,0.044120,0.040938,0.037204,0.032990,0.028434,0.023693,0.018936,0.014196,0.009456,0.004726,0.0), // RYAN BQM-34 FIREBEE WING AIRFOIL  
                                                    (0.0,0.007146,0.009006,0.011923,0.017462,0.025057,0.030364,0.034341,0.039772,0.042959,0.044580,0.045015,0.044521,0.043265,0.041381,0.038950,0.036047,0.032766,0.029134,0.025201,0.021035,0.016702,0.012285,0.007871,0.003648,0.0), // EH,0.0/9.0   
                                                    (0.0,0.018717,0.021725,0.028174,0.040959,0.060408,0.075100,0.087327,0.106241,0.119532,0.129842,0.138420,0.144805,0.148976,0.151687,0.152890,0.151443,0.146689,0.138889,0.127440,0.107707,0.071954,0.034263,0.016525,0.006452,0.0), // Griffith 30% thick symmetrical suction airfoil 
                                                    (0.0,0.012747,0.015652,0.019938,0.027670,0.037619,0.044265,0.049048,0.055144,0.058139,0.059000,0.058282,0.056321,0.053398,0.049709,0.045423,0.040674,0.035600,0.030332,0.024979,0.019670,0.014530,0.009736,0.005451,0.001983,0.0)); // 12% JOUKOWSKI AIRFOIL  

//   end corrected by Victor T  




type

{ TFreeKeelWizardDialog }

 TFreeKeelWizardDialog  = class(TForm)
                                 Panel1: TPanel;
                                 Panel3: TPanel;
                                 BitBtn1: TSpeedButton;
                                 BitBtn2: TSpeedButton;
                                 GroupBox1: TGroupBox;
                                 Label7: TLabel;
    _Label8: TLabel;
                                 Label9: TLabel;
    _Label10: TLabel;
                                 Label11: TLabel;
    _Label12: TLabel;
                                 Label13: TLabel;
    _Label14: TLabel;
                                 Label15: TLabel;
    _Label16: TLabel;
                                 Label18: TLabel;
    _Label19: TLabel;
                                 Label20: TLabel;
    _Label21: TLabel;
                                 Label22: TLabel;
    _Label23: TLabel;
                                 SpeedButton1: TSpeedButton;
                                 Label24: TLabel;
    _Label25: TLabel;
                                 PageControl: TPageControl;
                                 TabSheet1: TTabSheet;
                                 TabSheet2: TTabSheet;
                                 Viewport: TFreeViewport;
                                 Chart: TChart;
                                 Series1: TLineSeries;
                                 Series2: TLineSeries;
                                 Series3: TLineSeries;
                                 Series4: TLineSeries;
                                 Series5: TLineSeries;								 
                                 SpeedButton2: TSpeedButton;
    PageControl1: TPageControl;
    TabSheet3: TTabSheet;
    TabSheet4: TTabSheet;
    Label1: TLabel;
    ComboBox: TComboBox;
    Label2: TLabel;
    ComboBox1: TComboBox;
    Label17: TLabel;
    _ComboBox2: TComboBox;
    Label3: TLabel;
    Input1: TFreeNumInput;
    Label4: TLabel;
    Input2: TFreeNumInput;
    Label6: TLabel;
    Input4: TFreeNumInput;
    Label5: TLabel;
    Input3: TFreeNumInput;
    Label26: TLabel;
    Input5: TFreeNumInput;
    Label27: TLabel;
    Input6: TFreeNumInput;
    Label28: TLabel;
    TrackBar1: TTrackBar;
    Label8: TLabel;
    InputShape: TComboBox;
    Label12: TLabel;
    InputWing: TComboBox;
    Label14: TLabel;
    InputLength: TFreeNumInput;
    Label16: TLabel;
    InputPoints: TFreeNumInput;
    Label21: TLabel;
    InputDensity: TFreeNumInput;
    Button1: TButton;
    InputWeight: TFreeNumInput;
    Label23: TLabel;
    TrackBar2: TTrackBar;
    Label25: TLabel;
    InputDelta: TFreeNumInput;
    Button2: TButton;
    Label29: TLabel;
    Label10: TLabel;
    InputWingWidth: TFreeNumInput;
    Label19: TLabel;
    InputMaterial: TComboBox;
                                 procedure BitBtn1Click(Sender: TObject);
                                 procedure BitBtn2Click(Sender: TObject);
                                 procedure ComboBoxClick(Sender: TObject);
                                 procedure ComboBox1Click(Sender: TObject);
                                 procedure Input1AfterSetValue(Sender: TObject);
                                 procedure ViewportRequestExtents(Sender: TObject; var Min,Max: T3DCoordinate);
                                 procedure ViewportRedraw(Sender: TObject);
                                 procedure SpeedButton1Click(Sender: TObject);
                                 procedure Input5AfterSetValue(Sender: TObject);
                                 procedure Input6AfterSetValue(Sender: TObject);
                                 procedure TrackBar1Change(Sender: TObject);
                                 procedure SpeedButton2Click(Sender: TObject);
    procedure InputShapeClick(Sender: TObject);
    procedure InputMaterialChange(Sender: TObject);
    procedure InputWingClick(Sender: TObject);
    procedure InputDeltaAfterSetValue(Sender: TObject);
    procedure InputLengthAfterSetValue(Sender: TObject);
    procedure InputDensityAfterSetValue(Sender: TObject);
    procedure ViewportMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure ViewportMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);

                              private   { Private declarations }
                                 FFreeship         : TFreeShip;
                                 FProfile          : TFreeSpline;
                                 COG               : T2DCoordinate;
                                 Span              : TFloatType;
                                 Area,MeanChord    : TFloatType;
                                 GeomAspectRatio   : TFloatType;
                                 EffAspectRatio    : TFloatType;
                                 Volume            : TFloatType;
                                 VolCOG            : T3DCoordinate;
                                 WettedArea        : TFloatType;
                                 fDragBegin:TPoint;
                                 function FGetCols:Integer;
                                 function FGetRows:Integer;
                                 procedure UpdateData;
                              public    { Public declarations }
                                 str      : array [0..9] of string;
                                 Mesh     : array of array of T3DCoordinate;
                                 function Execute(Freeship:TFreeShip):Boolean;
                                 procedure SendToSurface(Surface:TFreeSubdivisionsurface);
                                 property Cols  : Integer read FGetCols;
                                 property Rows  : Integer read FGetRows;
                           end;

var FreeKeelWizardDialog: TFreeKeelWizardDialog;

implementation

{$IFnDEF FPC}
  {$R *.dfm}
{$ELSE}
  {$R *.lfm}
{$ENDIF}

function TFreeKeelWizardDialog.FGetCols:Integer;
begin
   Result:=Input6.AsInteger;
   if Result<3 then Result:=3;
end;{TFreeKeelWizardDialog.FGetCols}

function TFreeKeelWizardDialog.FGetRows:Integer;
begin
   Result:=Input5.AsInteger;
   if Result<2 then Result:=2;
end;{TFreeKeelWizardDialog.FGetRows}

procedure TFreeKeelWizardDialog.UpdateData;
const Cl2D=0.10;
var L,a,b      : TFloatType;
    I,J,Index  : Integer;
    VertInd    : Double;
    P          : T3DCoordinate;
    P_1,P_2    : T3DCoordinate;
    P_3,P_4    : T3DCoordinate;
    Angle      : TFloatType;
    Height     : TFloatType;
    Chord      : TFloatType;
    Start      : TFloatType;
    DeltaA     : TFloatType;
    MaxY       : TFloatType;
    P1,P2      : T2DCoordinate;
    Results    : TFreeIntersectionData;
    Plane      : T3DPlane;
    Spline     : TFreeSpline;
    VertDist   : Double;
//  Begin Victor T correction	
    Factor,Cl,Cd,wng         :double;
    r1,r2,dh,VolBulb,VolWing :double;
    Cx,Cy,Cn,Ct,C_d,mz,Kach,x,Cf0,Re   :double;
    sina,cosa,Cx0,Cya,aa,am,ama,ak     :double;
// End Victor T correction	
	

    procedure ProcessTriangle(P1,P2,P3:T3DCoordinate);
    var VolumeMoment : T3DCoordinate;
        Vol          : TFloatType;
        Center       : T3DCoordinate;
        ax,ay,az     : TFloatType;
    begin
       Center.X:=(P1.X+P2.X+P3.X)/3;
       Center.Y:=(P1.Y+P2.Y+P3.Y)/3;
       Center.Z:=(P1.Z+P2.Z+P3.Z)/3;
       Vol:=((P1.z)*(P2.x*P3.y-P2.y*P3.x)+
             (P1.y)*(P2.z*P3.x-P2.x*P3.z)+
             (P1.x)*(P2.y*P3.z-P2.z*P3.y))/6;
       if Vol<>0 then
       begin
          VolumeMoment.X:=0.75*Center.X*Vol;
          VolumeMoment.Y:=0.75*Center.Y*Vol;
          VolumeMoment.Z:=0.75*Center.Z*Vol;
          Volume:=Volume+Vol;
          VolCOG.X:=VolCOG.X+VolumeMoment.X;
          VolCOG.Y:=VolCOG.Y+VolumeMoment.Y;
          VolCOG.Z:=VolCOG.Z+VolumeMoment.Z;
       end;
       ax:=0.5*((P1.y-P2.y)*(P1.z+P2.z)+(P2.y-P3.y)*(P2.z+P3.z)+
                (P3.y-P1.y)*(P3.z+P1.z));
       ay:=0.5*((P1.z-P2.z)*(P1.x+P2.x)+(P2.z-P3.z)*(P2.x+P3.x)+
                (P3.z-P1.z)*(P3.x+P1.x));
       az:=0.5*((P1.x-P2.x)*(P1.y+P2.y)+(P2.x-P3.x)*(P2.y+P3.y)+
                (P3.x-P1.x)*(P3.y+P1.y));
       WettedArea:=WettedArea+Sqrt(ax*ax+ay*ay+az*az);
    end;{ProcessTriangle}

begin
   FProfile.Clear;
   FProfile.Color:=clBlack;
   FProfile.Fragments:=500;
   InputPoints.Enabled:=False;

   _label8.Caption:='';
   _label10.Caption:='';
   _label12.Caption:='';
   _label14.Caption:='';
   _label16.Caption:='';
   _label19.Caption:='';
   _label21.Caption:='';
   _label23.Caption:='';
   _label25.Caption:='';
   Series1.Clear;
   Series2.Clear;
   Series3.Clear;
   Series4.Clear;
   Series5.Clear;
   
   Factor:=1+Trackbar1.Position/Trackbar1.Max;

   if Combobox1.ItemIndex=0 then
   begin
      FProfile.Add(SetPoint(0,0,0));
      FProfile.Add(SetPoint(Input4.Value,0,-Input3.Value));
      FProfile.Knuckle[FProfile.NumberOfPoints-1]:=True;
      FProfile.Add(SetPoint(Input4.Value+Input2.Value,0,-Input3.Value));
      FProfile.Knuckle[FProfile.NumberOfPoints-1]:=True;
      FProfile.Add(SetPoint(Input1.Value,0,0));
      FProfile.Knuckle[FProfile.NumberOfPoints-1]:=True;
      FProfile.Add(FProfile.Point[0]);
   end else
   begin
      L:=Input3.Value;
      Case combobox1.ItemIndex of
         1 : a:=0.50*input1.Value;
         2 : a:=0.0;
         3 : a:=0.75*input1.Value;
         else a:=0.0;
      end;
      b:=Input1.Value-a;
      if a>0 then
      begin
         for I:=0 to 10 do
         begin
            Angle:=I*0.1*90;
            P.X:=a-a*cos(DegToRad(Angle));
            P.Y:=0.0;
            P.Z:=-L*sin(DegToRad(Angle));
            FProfile.Add(P);
         end;
      end else
      begin
         FProfile.Add(SetPoint(0,0,0));
         FProfile.Add(SetPoint(0,0,-L));
         FProfile.Knuckle[FProfile.NumberOfPoints-1]:=True;
      end;
      for I:=1 to 10 do
      begin
         Angle:=I*0.1*90;
         P.X:=a+b*sin(DegToRad(Angle));
         P.Y:=0.0;
         P.Z:=-L*cos(DegToRad(Angle));
         FProfile.Add(P);
      end;
      FProfile.Knuckle[FProfile.NumberOfPoints-1]:=True;
      FProfile.Add(FProfile.Point[0]);
   end;

   Area:=0;
   COG.X:=0.0;
   COG.Y:=0.0;
   MeanChord:=0.0;
   Span:=Input3.Value;
   GeomAspectRatio:=0.0;
   EffAspectRatio:=0.0;
   Volume:=0.0;
   Fillchar(VolCOG,SizeOf(T3DCoordinate),0);
   WettedArea:=0.0;
   MaxY:=0;

   if FProfile.NumberOfPoints>1 then
   begin
      Setlength(Mesh,Rows);
      for I:=1 to Rows do setlength(Mesh[I-1],Cols);

      // Vertical spacing between rows increases from bottom to top
      VertInd:=0;
      for I:=0 to Rows-1 do
      begin
         if I=0 then VertInd:=0
                else VertInd:=VertInd+Power(Factor,I-1);
      end;
      VertDist:=Span/VertInd;

      Index:=_ComboBox2.ItemIndex+1;
      Plane.a:=0.0;
      Plane.b:=0.0;
      Plane.c:=1.0;
      Spline:=TFreeSpline.Create;
      Spline.Capacity:=Nh;
      for I:=1 to Nh do
      begin
         P.X:=NacaProfiles[0,I];
         P.Y:=NacaProfiles[Index,I];
         P.Z:=0;
         Spline.Add(P);
      end;

      VertInd:=0;
      for I:=0 to Rows-1 do
      begin
         Chord:=0.0;
         Start:=0.0;
         if I=0 then VertInd:=0
                else VertInd:=VertInd+Power(Factor,I-1);
         Height:=Span-VertInd*VertDist;
         if (I>0) and (I<Rows-1) then
         begin
            Plane.d:=Height;
            if FProfile.IntersectPlane(Plane,Results) then if Results.NumberOfIntersections=2 then
            begin
               Chord:=Results.Points[1].X-Results.Points[0].X;
               Start:=Results.Points[0].X;
            end;
         end else if I=Rows-1 then
         begin
            Chord:=Input1.Value;
            Start:=0.0;
         end else
         begin
            if ComboBox1.ItemIndex=0 then
            begin
               Chord:=Input2.Value;
               Start:=Input4.Value;
            end else
            begin
               chord:=0.0;
               Case ComboBox1.ItemIndex of
                  1 : Start:=0.5*Input1.Value;
                  3 : start:=0.75*Input1.Value;
                  else Start:=0;
               end;
            end;
         end;

         for J:=0 to Cols-1 do
         begin
            P:=Spline.Value(J/(Cols-1));
            Mesh[I,J].X:=Start+Chord-P.X*Chord;
            Mesh[I,J].Y:=P.Y*Chord;
            Mesh[I,J].Z:=-Height;
            if Mesh[I,J].Y>MaxY then MaxY:=Mesh[I,J].Y;
         end;
      end;
      Spline.Destroy;

      // calculate volume, center of bouyancy and wetted area
      begin
         for I:=2 to Rows do
         begin
            for J:=2 to Cols do
            begin
               P_1:=Mesh[I-1,J-1];
               P_2:=Mesh[I-1,J-2];
               P_3:=Mesh[I-2,J-2];
               P_4:=Mesh[I-2,J-1];
               ProcessTriangle(P_1,P_2,P_3);
               ProcessTriangle(P_1,P_3,P_4);
               P_1.Y:=-P_1.Y;
               P_2.Y:=-P_2.Y;
               P_3.Y:=-P_3.Y;
               P_4.Y:=-P_4.Y;
               ProcessTriangle(P_1,P_4,P_3);
               ProcessTriangle(P_1,P_3,P_2);
            end;
         end;
      end;

      // Calculate planform area
      if Span<>0.0 then
      begin
         P:=FProfile.Value(1.0);
         P1.X:=P.X;
         P1.Y:=P.Z;
         for I:=0 to FProfile.Fragments do
         begin
            P:=FProfile.Value(I/FProfile.Fragments);
            P2.X:=P.X;
            P2.Y:=P.Z;
            DeltaA:=0.5*(P2.X+P1.X)*(P2.Y-P1.Y);
            Area:=Area+DeltaA;
            COG.X:=COG.X+DeltaA*0.25*(P2.X+P1.X);
            COG.Y:=COG.Y+DeltaA*0.50*(P2.Y+P1.Y);
            P1:=P2;
         end;
         if Area<>0 then
         begin
            COG.X:=COG.X/Area;
            COG.Y:=COG.Y/Area;
         end;
      end;

      if Span<>0 then MeanChord:=Area/Span;
      if MeanChord<>0 then GeomAspectRatio:=Span/MeanChord;
//  begin Victor T correction	 
      if Combobox.ItemIndex=0 then  EffAspectRatio:=2*GeomAspectRatio
                              else  EffAspectRatio:=GeomAspectRatio;
      if EffAspectRatio>0 then
      begin
 
// NACA45 Cx0=(2.1282043*10^(-7))*x^3-(1.7230937*10^(-5))*x^2+(7.2242606*10^(-4))*x+0.0071434
// NACA63 Cx0=(1.8921293*10^(-7))*x^3-(1.2522583*10^(-5))*x^2+(4.9670302*10^(-4))*x+0.0085356
// NACA64 Cx0=(6.7173371*10^(-8))*x^3-(9.2291526*10^(-7))*x^2+(2.2266167*10^(-4))*x+0.0101066
// NACA66 Cx0=(1.7417034*10^(-7))*x^3-(9.1730796*10^(-6))*x^2+(3.2534774*10^(-4))*x+0.0086993
// Jouk   Cx0=(1.4320923*10^(-7))*x^3-(1.0331613*10^(-5))*x^2+(5.1494225*10^(-4))*x+0.0091237
// Calculate lift and drag
    x:=2*MaxY/MeanChord*100.;
//        MessageDlg(FloatToStrF(x,ffFixed,6,3),mtInformation,[mbOk],0); 
//	Cx0:=0.01;
	Cx0:=1.4320923e-7*x*x*x-1.0331613e-5*x*x+5.1494225e-4*x+0.0091237;
{    x:=2*MaxY/MeanChord;	
	Re:=8e6;
	Cf0:=0.455/power(log10(Re),2.58);
	Cx0:=(2+2.4*x+17*x*x*x)*Cf0;	// по формуле Шольца
}	
//        MessageDlg(FloatToStrF(Cx0,ffFixed,6,3),mtInformation,[mbOk],0); 
	x:=EffAspectRatio;
	if x>=5 then x:=5;
	ak:=-0.0842831*x*x*x+0.0460527*x*x+0.6917343*x-0.001387;
	if x>2 then ak:=-0.0842831*8+0.0460527*4+0.6917343*2-0.001387;
	Cya:=0.0245642*x*x*x-0.3124828*x*x+1.773608*x+0.0041893;  
	ama:=1.8518519e-4*x*x*x+0.020754*x*x-0.300463*x+0.0023016;	   		 
        for I:=0 to 60 do
        begin
        	Angle:=I/2;
 		sina:=sin(Angle/180.*Pi);
		a:=1;
		if sina<0 then a:=-1;
		cosa:=cos(Angle/180.*Pi);
		Cx:=Cx0 + ak*sina*sina + abs(2.*sina*sina*sina);
		Cy:=Cya*sina+2*sina*sina*cosa*a;
		am:=ama*sina-a*sina*sina;
		Cn:=Cy*cosa + Cx*sina;
		Ct:=Cx*cosa - Cy*sina;
		if Cn=0 then C_d:=0.25
                        else C_d:=abs(am)/Cn;
		Kach:=Cy/Cx/10.;
            Series1.AddXY(Angle,Cy);
            Series2.AddXY(Angle,Cx);
            Series3.AddXY(Angle,-am);
            Series4.AddXY(Angle,C_d);
            Series5.AddXY(Angle,Kach);

         end;
      end;
//  Расчет объема киля/руля
   if Combobox1.ItemIndex=0 then
   begin
       Volume:=0;                     
//       V=h/3*(S1+sqrt(S1*S2)+S2)
//       S1=SUM[(r1+r2)*dh]*Input1.Value**2/2
//       S2=SUM[(r1+r2)*dh]*Input2.Value**2/2
//       V=SUM[(r1+r2)*dh]*Input3.Value/3/2*(Input1.Value**2+Input1.Value*Input2.Value+Input2.Value**2)
       for I:=2 to Nh do
       begin
         dh:=(NacaProfiles[0,I]-NacaProfiles[0,I-1]);
         r1:=NacaProfiles[_ComboBox2.ItemIndex+1,I];
         r2:=NacaProfiles[_ComboBox2.ItemIndex+1,I-1];
         Volume:=Volume+dh*(r1+r2);
       end;
         Volume:=Volume*Input3.Value/3*(Input1.Value*Input1.Value+Input1.Value*Input2.Value+Input2.Value*Input2.Value);
   end;
     if InputShape.ItemIndex=0 then begin
       if Combobox.ItemIndex=0 then  GroupBox1.Caption:=UserString(1119)+':'
                               else  GroupBox1.Caption:=UserString(1118)+':';
       Label18.Caption:=Str[0];
       Label20.Caption:=Str[1];
       Label22.Caption:=Str[2];
       Label7.Caption:=str[3];
       Label9.Caption:=str[4];
       Label11.Caption:=str[5];
       Label13.Caption:=str[6];
       Label15.Caption:=str[7];
       Label24.Caption:=str[8];
      _Label19.Caption:=FloatToStrF(Volume,ffFixed,7,3)+#32+VolStr(FFreeship.ProjectSettings.ProjectUnits);
      _Label21.Caption:=FloatToStrF(VolCOG.X/Volume/0.75,ffFixed,7,3)+', '+FloatToStrF(VolCOG.Z/Volume*2,ffFixed,7,3)+#32+LengthStr(FFreeship.ProjectSettings.ProjectUnits);
      _Label23.Caption:=FloatToStrF(WettedArea,ffFixed,7,3)+#32+AreaStr(FFreeship.ProjectSettings.ProjectUnits);
      _Label8.Caption:=FloatToStrF(Area,ffFixed,7,3)+#32+AreaStr(FFreeship.ProjectSettings.ProjectUnits);
      _Label10.Caption:=FloatToStrF(COG.X,ffFixed,7,3)+', '+FloatToStrF(COG.Y,ffFixed,7,3)+#32+LengthStr(FFreeship.ProjectSettings.ProjectUnits);
      _Label12.Caption:=FloatToStrF(MeanChord,ffFixed,7,3)+#32+LengthStr(FFreeship.ProjectSettings.ProjectUnits);
      _Label14.Caption:=FloatToStrF(GeomAspectRatio,ffFixed,7,3);
      _Label16.Caption:=FloatToStrF(EffAspectRatio,ffFixed,7,3);
      _Label25.Caption:=FloatToStrF(2*MaxY,ffFixed,7,3)+#32+LengthStr(FFreeship.ProjectSettings.ProjectUnits);
         end
        else begin
             if Combobox.ItemIndex=0 then  GroupBox1.Caption:=UserString(1119)+' '+UserString(1120)+':'
                                     else  GroupBox1.Caption:=UserString(1118)+' '+UserString(1120)+':';

        end;
   end;

// end Victor T correction	

   // Bulb wizard
   if InputShape.ItemIndex>0 then
   begin
      // 
      if InputShape.ItemIndex>1 then wng:=InputWingWidth.Value/2
                                else wng:=0;
// для кругового бульба
      FProfile.add(FProfile.Point[FProfile.NumberOfPoints-1]);
      FProfile.Knuckle[FProfile.NumberOfPoints-1]:=True;
      FProfile.add(FProfile.Point[FProfile.NumberOfPoints-3]);
      FProfile.Knuckle[FProfile.NumberOfPoints-1]:=True;
      FProfile.Add(SetPoint(Input4.Value+Input2.Value,0,-Input3.Value));
      FProfile.Knuckle[FProfile.NumberOfPoints-1]:=True;
      FProfile.Add(SetPoint(Input4.Value+Input2.Value+InputDelta.Value-InputLength.Value,0,-Input3.Value));
      FProfile.Knuckle[FProfile.NumberOfPoints-1]:=True;

// для кругового бульба и бульб-крыла
      if (InputShape.ItemIndex=1) or (InputShape.ItemIndex=3) then
      begin

       for I:=Nh downto 1 do
       begin
         P.X:=Input2.Value+Input4.Value+InputDelta.Value-NacaProfiles[0,I]*InputLength.Value;
         P.Y:=-NacaProfiles[InputWing.ItemIndex+1,I]*InputLength.Value/1.4142-wng;
         P.Z:=-Input3.Value;
         FProfile.Add(P);
         if I>Nh-2 then
           FProfile.Knuckle[FProfile.NumberOfPoints-1]:=True;
       end;

       for I:=1 to Nh do
       begin
         P.X:=Input2.Value+Input4.Value+InputDelta.Value-NacaProfiles[0,I]*InputLength.Value;
         P.Y:=NacaProfiles[InputWing.ItemIndex+1,I]*InputLength.Value/1.4142+wng;
         P.Z:=-Input3.Value;
         FProfile.Add(P);
       end;
       FProfile.Knuckle[FProfile.NumberOfPoints-2]:=True;
       FProfile.Knuckle[FProfile.NumberOfPoints-1]:=True;
       FProfile.Add(SetPoint(Input4.Value+Input2.Value+InputDelta.Value-InputLength.Value,0,-Input3.Value));
       FProfile.Knuckle[FProfile.NumberOfPoints-1]:=True;
      end;

      for I:=Nh downto 1 do
      begin
         P.X:=Input2.Value+Input4.Value+InputDelta.Value-NacaProfiles[0,I]*InputLength.Value;
         P.Y:=0;
         P.Z:=-Input3.Value-NacaProfiles[InputWing.ItemIndex+1,I]*InputLength.Value*14.14/(20+TrackBar2.Position);
         FProfile.Add(P);
      end;
      for I:=1 to Nh do
      begin
         P.X:=Input2.Value+Input4.Value+InputDelta.Value-NacaProfiles[0,I]*InputLength.Value;
         P.Y:=0;
         P.Z:=-Input3.Value+NacaProfiles[InputWing.ItemIndex+1,I]*InputLength.Value*14.14/(20+TrackBar2.Position);
         FProfile.Add(P);
      end;
      FProfile.Add(SetPoint(Input4.Value+Input2.Value+InputDelta.Value-InputLength.Value,0,-Input3.Value));
      FProfile.Knuckle[FProfile.NumberOfPoints-1]:=True;

      if InputShape.ItemIndex>1 then
      begin
       for I:=Nh downto 1 do
       begin
         P.X:=Input2.Value+Input4.Value+InputDelta.Value-NacaProfiles[0,I]*InputLength.Value;
         P.Y:=-wng;
         P.Z:=-Input3.Value-NacaProfiles[InputWing.ItemIndex+1,I]*InputLength.Value*14.14/(20+TrackBar2.Position);
         FProfile.Add(P);
         if I>Nh-2 then
           FProfile.Knuckle[FProfile.NumberOfPoints-1]:=True;
       end;
       for I:=1 to Nh do
       begin
         P.X:=Input2.Value+Input4.Value+InputDelta.Value-NacaProfiles[0,I]*InputLength.Value;
         P.Y:=-wng;
         P.Z:=-Input3.Value+NacaProfiles[InputWing.ItemIndex+1,I]*InputLength.Value*14.14/(20+TrackBar2.Position);
         FProfile.Add(P);
       end;
       FProfile.Knuckle[FProfile.NumberOfPoints-2]:=True;
       FProfile.Knuckle[FProfile.NumberOfPoints-1]:=True;
       FProfile.Add(SetPoint(Input4.Value+Input2.Value+InputDelta.Value-InputLength.Value,0,-Input3.Value));
       FProfile.Knuckle[FProfile.NumberOfPoints-1]:=True;
       for I:=Nh downto 1 do
       begin
         P.X:=Input2.Value+Input4.Value+InputDelta.Value-NacaProfiles[0,I]*InputLength.Value;
         P.Y:=wng;
         P.Z:=-Input3.Value-NacaProfiles[InputWing.ItemIndex+1,I]*InputLength.Value*14.14/(20+TrackBar2.Position);
         FProfile.Add(P);
         if I>Nh-2 then
           FProfile.Knuckle[FProfile.NumberOfPoints-1]:=True;
       end;
       for I:=1 to Nh do
       begin
         P.X:=Input2.Value+Input4.Value+InputDelta.Value-NacaProfiles[0,I]*InputLength.Value;
         P.Y:=wng;
         P.Z:=-Input3.Value+NacaProfiles[InputWing.ItemIndex+1,I]*InputLength.Value*14.14/(20+TrackBar2.Position);
         FProfile.Add(P);
       end;
       FProfile.Knuckle[FProfile.NumberOfPoints-2]:=True;
       FProfile.Knuckle[FProfile.NumberOfPoints-1]:=True;
       FProfile.Add(SetPoint(Input4.Value+Input2.Value+InputDelta.Value-InputLength.Value,0,-Input3.Value));
       FProfile.Knuckle[FProfile.NumberOfPoints-1]:=True;
      end;

      // begin calculate bulbous volume
      Volbulb:=0;    
//  расчет объема бульба
      if (InputShape.ItemIndex=1) or (InputShape.ItemIndex=3) then  begin
       for I:=2 to Nh do
       begin
         dh:=(NacaProfiles[0,I]-NacaProfiles[0,I-1])*InputLength.Value;;
         r1:=NacaProfiles[InputWing.ItemIndex+1,I]*InputLength.Value;
         r2:=NacaProfiles[InputWing.ItemIndex+1,I-1]*InputLength.Value;
         Volbulb:=Volbulb+dh*(r1*r1+r1*r2+r2*r2);
//         P.Z:=NacaProfiles[InputWing.ItemIndex+1,I]*InputLength.Value*20/(20+TrackBar2.Position);
       end;
         Volbulb:=Volbulb*3.1415926/3;
         Volbulb:=Volbulb*(20-Trackbar2.Position/2)/Trackbar2.Max*2;
      end;

//  расчет объема горизонтального крыла
      Volwing:=0;
      if wng<>0 then begin
        for I:=2 to Nh do
       begin
         dh:=(NacaProfiles[0,I]-NacaProfiles[0,I-1])*InputLength.Value;;
         r1:=NacaProfiles[InputWing.ItemIndex+1,I]*InputLength.Value;
         r2:=NacaProfiles[InputWing.ItemIndex+1,I-1]*InputLength.Value;
         Volwing:=Volwing+dh*(r1+r2)*2;
       end;
         Volwing:=Volwing*wng*(20-Trackbar2.Position/2)/Trackbar2.Max; 
      end; 
      // end calculate bulbous volume
       Label18.Caption:=UserString(1121);
       Label20.Caption:=UserString(1122);
       Label22.Caption:=UserString(1123);
       Label7.Caption:=' ';
       Label9.Caption:=' ';
       Label11.Caption:=' ';
       Label13.Caption:=' ';
       Label15.Caption:=' ';
       Label24.Caption:=' ';
       Volbulb:=Volbulb+Volwing;  // для бульб-крыла
       if Volume>=0.05 then _Label19.Caption:=FloatToStrF(Volume,ffFixed,8,4)+#32+VolStr(FFreeship.ProjectSettings.ProjectUnits)
                       else _Label19.Caption:=FloatToStrF(Volume,ffFixed,8,6)+#32+VolStr(FFreeship.ProjectSettings.ProjectUnits);
       if VolBulb*InputDensity.Value>=0.05 then begin
                                          _Label21.Caption:=FloatToStrF(VolBulb,ffFixed,8,4)+#32+VolStr(FFreeship.ProjectSettings.ProjectUnits);
                                          _Label23.Caption:=FloatToStrF(VolBulb*InputDensity.Value,ffFixed,8,3)+#32+WeightStr(FFreeship.ProjectSettings.ProjectUnits);
                                      end else begin
                                          _Label21.Caption:=FloatToStrF(VolBulb,ffFixed,8,6)+#32+VolStr(FFreeship.ProjectSettings.ProjectUnits);
                                          _Label23.Caption:=FloatToStrF(VolBulb*InputDensity.Value,ffFixed,8,6)+#32+WeightStr(FFreeship.ProjectSettings.ProjectUnits);  
       end;           
   end;

   Viewport.ZoomExtents;
end;{TFreeKeelWizardDialog.UpdateData}

function TFreeKeelWizardDialog.Execute(Freeship:TFreeShip):Boolean;
begin
   str[0]:=Label18.Caption;
   str[1]:=Label20.Caption;
   str[2]:=Label22.Caption;
   str[3]:=Label7.Caption;
   str[4]:=Label9.Caption;
   str[5]:=Label11.Caption;
   str[6]:=Label14.Caption;
   str[7]:=Label15.Caption;
   str[8]:=Label24.Caption;
   FFreeship:=Freeship;
   Chart.BottomAxis.Title.Caption:=UserString(933);
   Chart.LeftAxis.Title.Caption:=UserString(934);
   FProfile:=TFreeSpline.Create;
   ComboBoxClick(self);
   ComboBox1Click(self);
   ShowModal;
   FProfile.Destroy;
   FProfile:=nil;
   Result:=ModalResult=mrOK;   
end;{TFreeKeelWizardDialog.Execute}

procedure TFreeKeelWizardDialog.BitBtn1Click(Sender: TObject);
begin
   Modalresult:=mrOK;
end;{TFreeKeelWizardDialog.BitBtn1Click}

procedure TFreeKeelWizardDialog.BitBtn2Click(Sender: TObject);
begin
   Modalresult:=mrCancel;
end;{TFreeKeelWizardDialog.BitBtn2Click}

procedure TFreeKeelWizardDialog.ComboBoxClick(Sender: TObject);
begin
   UpdateData;
end;{TFreeKeelWizardDialog.ComboBoxClick}

procedure TFreeKeelWizardDialog.ComboBox1Click(Sender: TObject);
begin
   Input2.Enabled:=ComboBox1.ItemIndex=0;
   Input4.Enabled:=Input2.Enabled;
   if not Input2.Enabled then Input2.Value:=0.0;
   UpdateData;
end;{TFreeKeelWizardDialog.ComboBox1Click}

procedure TFreeKeelWizardDialog.Input1AfterSetValue(Sender: TObject);
begin
   UpdateData;
end;{TFreeKeelWizardDialog.Input1AfterSetValue}

procedure TFreeKeelWizardDialog.ViewportRequestExtents(Sender: TObject; var Min, Max: T3DCoordinate);
var I,J  : Integer;
    P    : T3DCoordinate;
begin
   if FProfile<>nil then if FProfile.NumberOfPoints>1 then
   begin
      FProfile.Extents(Min,Max);
      for I:=1 to Rows do
         for J:=1 to Cols do
      begin
         P:=Mesh[I-1,J-1];
         MinMax(P,Min,Max);
         P.Y:=-P.Y;
         MinMax(P,Min,Max);
      end;
   end;
   {
   if Max.X-Min.X<=0 then Max.X:=Min.X+1;
   if Max.Y-Min.Y<=0 then Max.Y:=Min.Y+1;
   if Max.Z-Min.Z<=0 then Max.Z:=Min.Z+1;
   }
end;{TFreeKeelWizardDialog.ViewportRequestExtents}

procedure TFreeKeelWizardDialog.ViewportRedraw(Sender: TObject);

    procedure DrawPoint(P:T3DCoordinate;Text:string);
    var Pt    : TPoint;
        Size  : Integer;
    begin
      Pt:=Viewport.Project(P);
      if Text<>'' then
      begin
         // Skip translation
         Viewport.FontName:='Arial';
         // End Skip translation
         Viewport.FontColor:=FFreeship.Preferences.HydrostaticsFontColor;
         size:=Round(Sqrt(Viewport.Zoom)*7);
         if size<2 then size:=2;
         Viewport.FontSize:=size;
      end;
      Size:=Round(Sqrt(Viewport.Zoom)*(FFreeship.Preferences.PointSize+1));
      if size<1 then size:=1;
      Viewport.BrushStyle:=bsClear;
      if Viewport.Printing then Size:=round(Size*Viewport.PrintResolution/150);
      Viewport.PenColor:=clDkGray;//Black;
      Viewport.BrushColor:=clWhite;
      Viewport.BrushStyle:=bsSolid;
      // Draw entire circle in white;
      Viewport.DrawingCanvas.Ellipse(Pt.X-Size,Pt.Y-Size,Pt.X+Size,Pt.Y+Size);
      // Draw upper left part in black
      Viewport.BrushColor:=clBlack;
      //Viewport.DrawingCanvas.Pie(Pt.X-Size,Pt.Y-Size,Pt.X+Size,Pt.Y+Size,Pt.X-1,Pt.Y-Size,Pt.X-Size,Pt.Y-1);
      Viewport.DrawingCanvas.Line(Pt.X-Size,Pt.Y,Pt.X+Size,Pt.Y);
      Viewport.DrawingCanvas.Line(Pt.X,Pt.Y-Size,Pt.X,Pt.Y-Size);
      // Draw lower right part in black
      //Viewport.DrawingCanvas.Pie(Pt.X-Size,Pt.Y-Size,Pt.X+Size,Pt.Y+Size,Pt.X-1,Pt.Y+Size,Pt.X+Size,Pt.Y-1);
      Viewport.BrushStyle:=bsClear;
      if Text<>'' then Viewport.DrawingCanvas.TextOut(Pt.X+2*size,Pt.Y,Text);
    end;{DrawPoint}

var Pts  : array of TPoint;
    P1,P2: T3DCoordinate;
    P3,P4: T3DCoordinate;
    I,J  : Integer;
    Pts100: array [0..99]of TPoint;
    dy,dz,wng: Extended;
begin
   // create aft profile
   if FProfile<>nil then
   begin

      if Viewport.ViewportMode=vmWireFrame then
      begin
         if FProfile.NumberOfPoints>1 then
         begin
            FProfile.Draw(Viewport);
            Setlength(Pts,Cols);
            for I:=1 to Rows do //if (I=0) or (I=Rows) then
            begin
               if I in [1,Rows] then Viewport.PenColor:=clBlack
                                else Viewport.PenColor:=clSilver;
               for J:=1 to Cols do Pts[J-1]:=Viewport.Project(Mesh[I-1,J-1]);
               Viewport.DrawingCanvas.Polyline(Pts);
               for J:=1 to Cols do
               begin
                  P1:=Mesh[I-1,J-1];
                  P1.Y:=-P1.Y;
                  Pts[J-1]:=Viewport.Project(P1);
               end;
               Viewport.DrawingCanvas.Polyline(Pts);
            end;
            Setlength(Pts,Rows);
            for J:=1 to Cols do //if not odd(J) then
            begin
               if J in [1,Cols] then Viewport.PenColor:=clBlack
                                else Viewport.PenColor:=clSilver;
               for I:=1 to Rows do Pts[I-1]:=Viewport.Project(Mesh[I-1,J-1]);
               Viewport.DrawingCanvas.Polyline(Pts);
               for I:=1 to Rows do
               begin
                  P1:=Mesh[I-1,J-1];
                  P1.Y:=-P1.Y;
                  Pts[I-1]:=Viewport.Project(P1);
               end;
               Viewport.DrawingCanvas.Polyline(Pts);
            end;
            DrawPoint(SetPoint(COG.X,0,COG.Y),'');
//Bulb intersections
            Viewport.PenColor:=clGray;
            if InputShape.ItemIndex>0 then
            Begin
              if InputShape.ItemIndex>1 then
                wng:=InputWingWidth.Value/2
              else
                wng:=0;


              for i:=2 to Nh-1 do
              begin
                P1.X:=Input2.Value+Input4.Value+InputDelta.Value-NacaProfiles[0,I]*InputLength.Value;
                if (InputShape.ItemIndex=1) or (InputShape.ItemIndex=3) then
                begin
                for j:=0 to 24 do
                begin
                  dy:=Cos(Pi/48*j)*NacaProfiles[InputWing.ItemIndex+1,I]*InputLength.Value/1.4142;
                  dz:=Sin(Pi/48*j)*NacaProfiles[InputWing.ItemIndex+1,I]*InputLength.Value*14.14/(20+TrackBar2.Position);

                  P1.Y:=-dy-wng;
                  P1.Z:=-Input3.Value - dz;
                  Pts100[j]:=Viewport.Project(P1);

                  P1.Z:=-Input3.Value + dz;
                  Pts100[99-j]:=Viewport.Project(P1);

                  P1.y:=dy+wng;
                  P1.Z:=-Input3.Value - dz;
                  Pts100[49-j]:=Viewport.Project(P1);
                  P1.Z:=-Input3.Value + dz;
                  Pts100[50+j]:=Viewport.Project(P1);
                end;
                Viewport.DrawingCanvas.Polyline(Pts100);
                end
                else
                if (InputShape.ItemIndex=2) then
                begin
                  SetLength(Pts,5);
                  dz:=NacaProfiles[InputWing.ItemIndex+1,I]*InputLength.Value*14.14/(20+TrackBar2.Position);
                  P1.Y:=-wng;
                  P1.Z:=-Input3.Value - dz;
                  Pts[0]:=Viewport.Project(P1);
                  P1.Z:=-Input3.Value + dz;
                  Pts[1]:=Viewport.Project(P1);
                  P1.Y:=wng;
                  P1.Z:=-Input3.Value + dz;
                  Pts[2]:=Viewport.Project(P1);
                  P1.Z:=-Input3.Value -  dz;
                  Pts[3]:=Viewport.Project(P1);
                  Pts[4]:=Pts[0];

                  Viewport.DrawingCanvas.Polyline(Pts);
                end;
              end;
            end;
         end;
      end else
      begin
         for I:=2 to Rows do
         begin
            for J:=2 to Cols do
            begin
               P1:=Mesh[I-1][J-1];
               P2:=Mesh[I-1][J-2];
               P3:=Mesh[I-2][J-2];
               P4:=Mesh[I-2][J-1];
               Viewport.ShadeTriangle(P1,P2,P3,GetRValue(FFreeship.Preferences.LayerColor),GetGValue(FFreeship.Preferences.LayerColor),GetBValue(FFreeship.Preferences.LayerColor));
               Viewport.ShadeTriangle(P1,P3,P4,GetRValue(FFreeship.Preferences.LayerColor),GetGValue(FFreeship.Preferences.LayerColor),GetBValue(FFreeship.Preferences.LayerColor));
               P1.Y:=-P1.Y;
               P2.Y:=-P2.Y;
               P3.Y:=-P3.Y;
               P4.Y:=-P4.Y;
               Viewport.ShadeTriangle(P1,P2,P3,GetRValue(FFreeship.Preferences.LayerColor),GetGValue(FFreeship.Preferences.LayerColor),GetBValue(FFreeship.Preferences.LayerColor));
               Viewport.ShadeTriangle(P1,P3,P4,GetRValue(FFreeship.Preferences.LayerColor),GetGValue(FFreeship.Preferences.LayerColor),GetBValue(FFreeship.Preferences.LayerColor));
            end;
         end;
      end;
   end;

end;{TFreeKeelWizardDialog.ViewportRedraw}

procedure TFreeKeelWizardDialog.SpeedButton1Click(Sender: TObject);
var Str  : String;
begin
   Str:=Lowercase(Combobox.Text)+#32+_Combobox2.Text;
   FFreeship.Edit.CreateUndoObject('Add '+str,True);
   SendToSurface(FFreeship.Surface);
   FFreeship.FileChanged:=True;
   if Assigned(FFreeship.OnUpdateGeometryInfo) then FFreeship.OnUpdateGeometryInfo(FFreeship);
   FFreeship.ProjectSettings.ProjectDraft:=FFreeship.ProjectSettings.ProjectDraft+Input3.Value;
   FFreeship.Redraw;
end;{TFreeKeelWizardDialog.SpeedButton1Click}

procedure TFreeKeelWizardDialog.Input5AfterSetValue(Sender: TObject);
begin
   UpdateData;
end;{TFreeKeelWizardDialog.Input5AfterSetValue}

procedure TFreeKeelWizardDialog.Input6AfterSetValue(Sender: TObject);
begin
   UpdateData;
end;{TFreeKeelWizardDialog.Input6AfterSetValue}

procedure TFreeKeelWizardDialog.TrackBar1Change(Sender: TObject);
begin
   UpdateData;
end;{TFreeKeelWizardDialog.TrackBar1Change}

procedure TFreeKeelWizardDialog.SendToSurface(Surface:TFreeSubdivisionsurface);
var I,J           : Integer;
    FacePoints    : TFasterList;
    Grid          : TFreeSubdivisionGrid;
    P             : TFreeSubdivisionControlPoint;
    Edge          : TFreeSubdivisionedge;
    Layer         : TFreeSubdivisionLayer;
    P3D           : T3DCoordinate;
    Str           : string;
    PrevCursor    : TCursor;


    procedure AddRoundBulb;
    var P, P1, P2: TFreeSubdivisionControlPoint;
       PP:array[0..3, 2..Nh-1] of TFreeSubdivisionControlPoint;
       i:integer;
       dx,dy,dZ,kZ,kR:Extended;
        FacePoints    : TFasterList;
    begin

        Layer.UseInHydrostatics:=False;
        dX:=Input4.Value+Input2.Value+InputDelta.Value;
        dY:=0;
        dZ:=-Input3.Value;
        kZ := 14.14/(20+TrackBar2.Position);
        kR := 2.11; //sqrt(2);

        P1:=TFreeSubdivisionControlPoint.Create(Surface);
        Surface.AddControlPoint(P1);
        P1.Coordinate:=SetPoint(dX,0,dZ);

        P2:=TFreeSubdivisionControlPoint.Create(Surface);
        Surface.AddControlPoint(P2);
        P2.Coordinate:=SetPoint(dX-InputLength.Value,0,dZ);

        for i:=2 to Nh-1 do
        begin
          P:=TFreeSubdivisionControlPoint.Create(Surface);
          Surface.AddControlPoint(P);
          P.Coordinate:=SetPoint(
            dX - InputLength.Value * NacaProfiles[0,I],
            dY ,
            dZ + kZ * NacaProfiles[InputWing.ItemIndex +1, I] * InputLength.Value *kR);
          PP[0,i]:=P;

          P:=TFreeSubdivisionControlPoint.Create(Surface);
          Surface.AddControlPoint(P);
          P.Coordinate:=SetPoint(
            dX - InputLength.Value * NacaProfiles[0,I],
            dY + NacaProfiles[InputWing.ItemIndex +1, I] * InputLength.Value *kR/1.4142,
            dZ);
          PP[1,i]:=P;

          P:=TFreeSubdivisionControlPoint.Create(Surface);
          Surface.AddControlPoint(P);
          P.Coordinate:=SetPoint(
            dX - InputLength.Value * NacaProfiles[0,I],
            dY ,
            dZ - kZ * NacaProfiles[InputWing.ItemIndex +1, I] * InputLength.Value *kR) ;
          PP[2,i]:=P;

          P:=TFreeSubdivisionControlPoint.Create(Surface);
          Surface.AddControlPoint(P);
          P.Coordinate:=SetPoint(
            dX - InputLength.Value * NacaProfiles[0,I],
            dY - NacaProfiles[InputWing.ItemIndex +1, I] * InputLength.Value *kR/1.4142,
            dZ );
          PP[3,i]:=P;

        end;

        FacePoints:=TFasterList.Create;
        begin
          FacePoints.Clear;
          FacePoints.Add(P1);
          FacePoints.Add(PP[0,2]);
          FacePoints.Add(PP[1,2]);
          Surface.AddControlFace(FacePoints,True,Layer);

          FacePoints.Clear;
          FacePoints.Add(P1);
          FacePoints.Add(PP[1,2]);
          FacePoints.Add(PP[2,2]);
          Surface.AddControlFace(FacePoints,True,Layer);

          FacePoints.Clear;
          FacePoints.Add(P1);
          FacePoints.Add(PP[2,2]);
          FacePoints.Add(PP[3,2]);
          Surface.AddControlFace(FacePoints,True,Layer);

          FacePoints.Clear;
          FacePoints.Add(P1);
          FacePoints.Add(PP[3,2]);
          FacePoints.Add(PP[0,2]);
          Surface.AddControlFace(FacePoints,True,Layer);



          for i:=2 to Nh-2 do
          begin
            FacePoints.Clear;
            FacePoints.Add(PP[0,i]);
            FacePoints.Add(PP[0,i+1]);
            FacePoints.Add(PP[1,i+1]);
            FacePoints.Add(PP[1,i]);
            Surface.AddControlFace(FacePoints,True,Layer);

            FacePoints.Clear;
            FacePoints.Add(PP[1,i]);
            FacePoints.Add(PP[1,i+1]);
            FacePoints.Add(PP[2,i+1]);
            FacePoints.Add(PP[2,i]);
            Surface.AddControlFace(FacePoints,True,Layer);

            FacePoints.Clear;
            FacePoints.Add(PP[2,i]);
            FacePoints.Add(PP[2,i+1]);
            FacePoints.Add(PP[3,i+1]);
            FacePoints.Add(PP[3,i]);
            Surface.AddControlFace(FacePoints,True,Layer);

            FacePoints.Clear;
            FacePoints.Add(PP[3,i]);
            FacePoints.Add(PP[3,i+1]);
            FacePoints.Add(PP[0,i+1]);
            FacePoints.Add(PP[0,i]);
            Surface.AddControlFace(FacePoints,True,Layer);


          end;

          FacePoints.Clear;
          FacePoints.Add(P2);
          FacePoints.Add(PP[0,Nh-1]);
          FacePoints.Add(PP[1,Nh-1]);
          Surface.AddControlFace(FacePoints,True,Layer);

          FacePoints.Clear;
          FacePoints.Add(P2);
          FacePoints.Add(PP[1,Nh-1]);
          FacePoints.Add(PP[2,Nh-1]);
          Surface.AddControlFace(FacePoints,True,Layer);

          FacePoints.Clear;
          FacePoints.Add(P2);
          FacePoints.Add(PP[2,Nh-1]);
          FacePoints.Add(PP[3,Nh-1]);
          Surface.AddControlFace(FacePoints,True,Layer);

          FacePoints.Clear;
          FacePoints.Add(P2);
          FacePoints.Add(PP[3,Nh-1]);
          FacePoints.Add(PP[0,Nh-1]);
          Surface.AddControlFace(FacePoints,True,Layer);

         end;
        FacePoints.Destroy;

    end;

    procedure AddWingBulb;
    var P, P1, P2, p3,p4: TFreeSubdivisionControlPoint;
       PP:array[0..4, 1..Nh-1] of TFreeSubdivisionControlPoint;
       i:integer;
       dx,dy,dZ,kZ,kR, wng:Extended;
       FacePoints    : TFasterList;
    begin

        Layer.UseInHydrostatics:=True;
        dX:=Input4.Value+Input2.Value+InputDelta.Value;
        dY:=0;
        dZ:=-Input3.Value;
        kZ := 14.14/(20+TrackBar2.Position);
        kR := sqrt(2);
        if InputShape.ItemIndex>1 then
          wng:=InputWingWidth.Value/2
        else
          wng:=0;

        P1:=TFreeSubdivisionControlPoint.Create(Surface);
        Surface.AddControlPoint(P1);
        P1.Coordinate:=SetPoint(dX,wng,dZ);

        P2:=TFreeSubdivisionControlPoint.Create(Surface);
        Surface.AddControlPoint(P2);
        P2.Coordinate:=SetPoint(dX-InputLength.Value,wng,dZ);

        P3:=TFreeSubdivisionControlPoint.Create(Surface);
        Surface.AddControlPoint(P3);
        P3.Coordinate:=SetPoint(dX,0,dZ);

        P4:=TFreeSubdivisionControlPoint.Create(Surface);
        Surface.AddControlPoint(P4);
        P4.Coordinate:=SetPoint(dX-InputLength.Value,0,dZ);

        for i:=2 to Nh-1 do
        begin
          P:=TFreeSubdivisionControlPoint.Create(Surface);
          Surface.AddControlPoint(P);
          P.Coordinate:=SetPoint(
            dX - InputLength.Value * NacaProfiles[0,I],
            dY ,
            dZ + kZ * NacaProfiles[InputWing.ItemIndex +1, I] * InputLength.Value *kR);
          PP[0,i]:=P;

          P:=TFreeSubdivisionControlPoint.Create(Surface);
          Surface.AddControlPoint(P);
          P.Coordinate:=SetPoint(
            dX - InputLength.Value * NacaProfiles[0,I],
            dY + Wng,
            dZ + kZ * NacaProfiles[InputWing.ItemIndex +1, I] * InputLength.Value *kR);
          PP[1,i]:=P;

          P:=TFreeSubdivisionControlPoint.Create(Surface);
          Surface.AddControlPoint(P);
          if InputShape.ItemIndex=3 then
            P.Coordinate:=SetPoint(
              dX - InputLength.Value * NacaProfiles[0,I],
              dY + NacaProfiles[InputWing.ItemIndex +1, I] * InputLength.Value *kR+wng,
              dZ)
          else
            P.Coordinate:=SetPoint(
              dX - InputLength.Value * NacaProfiles[0,I],
              dY + Wng,
              dZ);
          PP[2,i]:=P;


          P:=TFreeSubdivisionControlPoint.Create(Surface);
          Surface.AddControlPoint(P);
          P.Coordinate:=SetPoint(
            dX - InputLength.Value * NacaProfiles[0,I],
            dY + Wng,
            dZ - kZ * NacaProfiles[InputWing.ItemIndex +1, I] * InputLength.Value *kR);
          PP[3,i]:=P;

          P:=TFreeSubdivisionControlPoint.Create(Surface);
          Surface.AddControlPoint(P);
          P.Coordinate:=SetPoint(
            dX - InputLength.Value * NacaProfiles[0,I],
            dY ,
            dZ - kZ * NacaProfiles[InputWing.ItemIndex +1, I] * InputLength.Value *kR);
          PP[4,i]:=P;
        end;

        FacePoints:=TFasterList.Create;
        begin
          FacePoints.Clear;
          FacePoints.Add(P1);
          FacePoints.Add(P3);
          FacePoints.Add(PP[0,2]);
          FacePoints.Add(PP[1,2]);
          Surface.AddControlFace(FacePoints,True,Layer);

          FacePoints.Clear;
          FacePoints.Add(P1);
          FacePoints.Add(PP[1,2]);
          FacePoints.Add(PP[2,2]);
          Surface.AddControlFace(FacePoints,True,Layer);

          FacePoints.Clear;
          FacePoints.Add(P1);
          FacePoints.Add(PP[2,2]);
          FacePoints.Add(PP[3,2]);
          Surface.AddControlFace(FacePoints,True,Layer);

          FacePoints.Clear;
          FacePoints.Add(P3);
          FacePoints.Add(P1);
          FacePoints.Add(PP[3,2]);
          FacePoints.Add(PP[4,2]);
          Surface.AddControlFace(FacePoints,True,Layer);

          for i:=2 to Nh-2 do
          begin
            FacePoints.Clear;
            FacePoints.Add(PP[0,i]);
            FacePoints.Add(PP[0,i+1]);
            FacePoints.Add(PP[1,i+1]);
            FacePoints.Add(PP[1,i]);
            Surface.AddControlFace(FacePoints,True,Layer);

            FacePoints.Clear;
            FacePoints.Add(PP[1,i]);
            FacePoints.Add(PP[1,i+1]);
            FacePoints.Add(PP[2,i+1]);
            FacePoints.Add(PP[2,i]);
            Surface.AddControlFace(FacePoints,True,Layer);

            FacePoints.Clear;
            FacePoints.Add(PP[2,i]);
            FacePoints.Add(PP[2,i+1]);
            FacePoints.Add(PP[3,i+1]);
            FacePoints.Add(PP[3,i]);
            Surface.AddControlFace(FacePoints,True,Layer);

            FacePoints.Clear;
            FacePoints.Add(PP[3,i]);
            FacePoints.Add(PP[3,i+1]);
            FacePoints.Add(PP[4,i+1]);
            FacePoints.Add(PP[4,i]);
            Surface.AddControlFace(FacePoints,True,Layer);
          end;

          FacePoints.Clear;
          FacePoints.Add(P2);
          FacePoints.Add(P4);
          FacePoints.Add(PP[0,Nh-1]);
          FacePoints.Add(PP[1,Nh-1]);
          Surface.AddControlFace(FacePoints,True,Layer);

          FacePoints.Clear;
          FacePoints.Add(P2);
          FacePoints.Add(PP[1,Nh-1]);
          FacePoints.Add(PP[2,Nh-1]);
          Surface.AddControlFace(FacePoints,True,Layer);

          FacePoints.Clear;
          FacePoints.Add(P2);
          FacePoints.Add(PP[2,Nh-1]);
          FacePoints.Add(PP[3,Nh-1]);
          Surface.AddControlFace(FacePoints,True,Layer);

          FacePoints.Clear;
          FacePoints.Add(P4);
          FacePoints.Add(P2);
          FacePoints.Add(PP[3,Nh-1]);
          FacePoints.Add(PP[4,Nh-1]);
          Surface.AddControlFace(FacePoints,True,Layer);

         end;
        FacePoints.Destroy;

    end;

begin 

   PrevCursor:=Screen.Cursor;
   try
      Str:=Lowercase(Combobox.Text)+#32+_Combobox2.Text;
      Layer:=Surface.AddNewLayer;
      Str:=Combobox1.Text+#32+Lowercase(ComboBox.Text)+#32+_ComboBox2.Text;
      Layer.Name:=Str;
      Layer.Color:=FFreeship.Preferences.LayerColor;
      Setlength(Grid,Rows+2);
      for I:=1 to Rows+2 do Setlength(Grid[I-1],Cols);
      for I:=2 to Rows+1 do
      begin
         if (I=2) and (ComboBox1.ItemIndex>0) then
         begin
            P:=TFreeSubdivisionControlPoint.Create(Surface);
            Surface.AddControlPoint(P);
            P.Coordinate:=Mesh[I-2,0];
            Grid[I-1,0]:=P;
            for J:=2 to Cols do Grid[I-1][J-1]:=grid[I-1][0];
         end else
         begin
            for J:=1 to Cols do
            begin
               P:=TFreeSubdivisionControlPoint.Create(Surface);
               Surface.AddControlPoint(P);
               P.Coordinate:=Mesh[I-2,J-1];
               Grid[I-1,J-1]:=P;
            end;
         end;
      end;
      for J:=1 to Cols do
      begin
         if ComboBox1.ItemIndex=0 then
         begin
            // Close bottom
            P:=Grid[1][J-1] as TFreeSubdivisionControlpoint;
            if abs(P.Coordinate.Y)<1e-4then
            begin
               // do nothing
               Grid[0,J-1]:=P;
            end else
            begin
               // close at bottom
               P3D:=P.Coordinate;
               P3D.Y:=0.0;
               P:=TFreeSubdivisionControlPoint.Create(Surface);
               Surface.AddControlPoint(P);
               P.Coordinate:=P3D;
               Grid[0,J-1]:=P;
            end;
         end else Grid[0,J-1]:=Grid[1,J-1];

         // Close Top
         P:=Grid[Rows][J-1] as TFreeSubdivisionControlpoint;
         if abs(P.Coordinate.Y)<1e-4then
         begin
            // do nothing
            Grid[Rows+1,J-1]:=P;
         end else
         begin
            // close at top
            P3D:=P.Coordinate;
            P3D.Y:=0.0;
            P:=TFreeSubdivisionControlPoint.Create(Surface);
            Surface.AddControlPoint(P);
            P.Coordinate:=P3D;
            Grid[Rows+1,J-1]:=P;
         end;
      end;
      FacePoints:=TFasterList.Create;
      for I:=2 to Rows+2 do
      begin
         for J:=2 to Cols do
         begin
            FacePoints.Clear;
            if FacePoints.IndexOf(Grid[I-1,J-1])=-1 then FacePoints.Add(Grid[I-1,J-1]);
            if FacePoints.IndexOf(Grid[I-1,J-2])=-1 then FacePoints.Add(Grid[I-1,J-2]);
            if FacePoints.IndexOf(Grid[I-2,J-2])=-1 then FacePoints.Add(Grid[I-2,J-2]);
            if FacePoints.IndexOf(Grid[I-2,J-1])=-1 then FacePoints.Add(Grid[I-2,J-1]);
            if FacePoints.Count>=3 then Surface.AddControlFace(FacePoints,True,Layer);
         end;
      end;
      FacePoints.Destroy;

      // set crease edges at top and bottom
      for J:=2 to Cols do
      begin
         if ComboBox1.ItemIndex=0 then
         begin
            Edge:=Surface.EdgeExists(Grid[1,J-2],Grid[1,J-1]);
            if Edge<>nil then Edge.Crease:=true;
         end;
         Edge:=Surface.EdgeExists(Grid[Rows,J-2],Grid[Rows,J-1]);
         if Edge<>nil then Edge.Crease:=true;
      end;
      if InputShape.ItemIndex>0 then
      Begin
        Layer:=Surface.AddNewLayer;
        Layer.Name:=InputShape.Text+'_'+InputWing.Text;
        Layer.Color:=FFreeship.Preferences.LayerColor;
        if InputShape.ItemIndex=1 then
          AddRoundBulb
        else
          AddWingBulb;


      end;
   finally
      Screen.Cursor:=prevCursor;
   end;
end;{TFreeKeelWizardDialog.SendToSurface}

procedure TFreeKeelWizardDialog.SpeedButton2Click(Sender: TObject);
var Surface : TFreeSubdivisionSurface;
    Faces   : TFasterList;
    I       : Integer;
begin
   Surface:=TFreeSubdivisionSurface.Create;
   SendToSurface(Surface);
   Faces:=TFasterList.Create;
   Faces.Capacity:=Surface.NumberOfControlFaces;
   for I:=1 to Surface.NumberOfControlFaces do Faces.Add(Surface.ControlFace[I-1]);
   FFreeship.SavePart(Faces);
   Faces.Destroy;
   Surface.Destroy;
end;{TFreeKeelWizardDialog.SendToSurface}

procedure TFreeKeelWizardDialog.InputShapeClick(Sender: TObject);
begin
   UpdateData;
   InputWingWidth.enabled:=InputShape.ItemIndex>1;
end;

procedure TFreeKeelWizardDialog.InputMaterialChange(Sender: TObject);
begin
  InputDensity.Enabled:=False;
  case InputMaterial.ItemIndex of
    0: InputDensity.Value := 11.35;
    1: InputDensity.Value := 7.2;
    2: InputDensity.Value := 19.3;
    else InputDensity.Enabled:=True
  end;
  UpdateData;
end;

procedure TFreeKeelWizardDialog.InputWingClick(Sender: TObject);
begin
   UpdateData;
end;

procedure TFreeKeelWizardDialog.InputDeltaAfterSetValue(Sender: TObject);
begin
   UpdateData;
end;

procedure TFreeKeelWizardDialog.InputLengthAfterSetValue(Sender: TObject);
begin
   UpdateData;
end;

procedure TFreeKeelWizardDialog.InputDensityAfterSetValue(Sender: TObject);
begin
   UpdateData;
end;

procedure TFreeKeelWizardDialog.ViewportMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if (ssRight in Shift) then
  begin
    fDragBegin.X:=X;
    fDragBegin.Y:=Y;
  end;
end;

procedure TFreeKeelWizardDialog.ViewportMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
  if (ssRight in Shift) then
  begin
         Viewport.Pan:=Point(Viewport.Pan.X+X-fDragBegin.X, Viewport.Pan.Y+Y-fDragBegin.Y);
    fDragBegin.X:=X;
    fDragBegin.Y:=Y;

  end;
end;

end.